[U-Boot] [PATCH 24/30] dm: sandbox: Add driver-model block-device support for sandbox
Simon Glass
sjg at chromium.org
Mon Feb 29 05:19:07 CET 2016
Hi Stephen,
On 16 February 2016 at 16:34, Stephen Warren <swarren at wwwdotorg.org> wrote:
> On 02/14/2016 07:16 PM, Simon Glass wrote:
>>
>> Update the host driver to support driver model for block devices. A future
>> commit will remove the old code, but for now it is useful to be able to
>> use
>> it both with and without CONFIG_BLK.
>
>
>> diff --git a/drivers/block/sandbox.c b/drivers/block/sandbox.c
>
>
>> +#ifdef CONFIG_BLK
>> +int host_dev_bind(int devnum, char *filename)
>> +{
>> + struct host_block_dev *host_dev;
>> + struct udevice *dev;
>> + char dev_name[20], *str, *fname;
>
> ...
>>
>> + sprintf(dev_name, "host%d", devnum);
>
>
> Use snprintf() to avoid overflow?
OK.
>
>> + str = strdup(dev_name);
>> + if (!str)
>> + return -ENOMEM;
>> + fname = strdup(filename);
>> + if (!fname) {
>> + free(str);
>> + return -ENOMEM;
>> + }
>
>
> Do those get free()d somewhere on unbind?
>
> Actually, I don't see any unbind() function in this file (even before this
> patch).
The unbinding is at the top of this function - if you overwrite an
existing device. It's a bit clunky. I suspect we can do better when
everything is on driver model.
There is no free(). This is a memory leak. It only affects sandbox though.
Actually we have similar memory leaks elsewhere when device names are
allocated, for example with GPIO. I haven't considered it a high
priority so far, but one possible fix is to add a device flag to
indicate that the name should be free on unbind().
Regards,
Simon
More information about the U-Boot
mailing list