Thread (1 message) 1 message, 1 author, 2017-12-12

Re: [PATCHv2] virtio_mmio: fix devm cleanup

From: weiping zhang <hidden>
Date: 2017-12-12 15:04:32

2017-12-12 22:45 GMT+08:00 Mark Rutland [off-list ref]:
On Tue, Dec 12, 2017 at 10:26:24PM +0800, weiping zhang wrote:
quoted
2017-12-12 21:45 GMT+08:00 Mark Rutland [off-list ref]:
Hi Mark,
Hi,
quoted
thanks your patch, I dig into these three devm_xxx funciton,
all of them represented by a struct devres as following,

struct devres_node {
        struct list_head                entry;
        dr_release_t                    release;
#ifdef CONFIG_DEBUG_DEVRES
        const char                      *name;
        size_t                          size;
#endif

};

struct devres {
        struct devres_node              node;
        /* -- 3 pointers */
        unsigned long long              data[]; /* guarantee ull alignment */
};
quoted
2) devm_kzalloc -> devm_kmalloc

dr = alloc_dr(devm_kmalloc_release, size, gfp, dev_to_node(dev));
"devm_kmalloc_release" is noop, do nothing.
Please note that the release function is there to perform cleanup prior
to the devm infrastructure releasing the memory.

The devm_kmalloc_release function is a no-op since nothing has to be
done prior to memory being freed, but the memory itself is still freed.

In alloc_dr(), the struct devres is allocated together with the memory,
since alloc_dr() does:

        size_t tot_size = sizeof(struct devres) + size;
        struct devres *dr;

        dr = kmalloc_node_track_caller(tot_size, gfp, nid);

        return dr->data;

... where dr->data points at the memory after the struct devres.

Later, in release_nodes() we do:

        list_for_each_entry_safe_reverse(dr, tmp, &todo, node.entry) {
                devres_log(dev, &dr->node, "REL");
                dr->node.release(dev, dr->data);
                kfree(dr);
        }

... which will invoke the no-op devm_kmalloc_release, then free the
devres allocation, including the dr->data memory the user requested.
quoted
so for case 2) above, we need a devm_kfree() before call
register_virtio_device
As above, I do not believe that is the case.
Oh I see, thanks your detail explanation. Thanks a lot.
Thanks,
Mark.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help