[U-Boot] [PATCH 24/30] dm: sandbox: Add driver-model block-device support for sandbox

Stephen Warren swarren at wwwdotorg.org
Wed Feb 17 00:34:51 CET 2016


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?

> +	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).


More information about the U-Boot mailing list