On Fri, Jan 29, 2021 at 2:01 PM <quanyang.wang@xxxxxxxxxxxxx> wrote:Thanks for your comment. I didn't catch the double free. Would you please point it out?
From: Quanyang Wang <quanyang.wang@xxxxxxxxxxxxx>Thanks for the report.
In gpiochip_add_data_with_key, we should check the return value of
dev_set_name to ensure that device name is allocated successfully
and then add a label on the error path to free device name to fix
kmemleak as below:
Unfortunately...
+ ret = dev_set_name(&gdev->dev, GPIOCHIP_NAME "%d", gdev->id);...
+ if (ret)
+ goto err_free_ida;
+err_free_dev_name:...this approach seems to create a possible double free if I'm not mistaken.
+ kfree(dev_name(&gdev->dev));
The idea is that device name should be cleaned in kobject ->release()
callback when device is put.
Can you elaborate?