Re: [PATCH v3 03/16] fpga: mgr: API change to replace fpga load functions with single function

From: Alan Tull
Date: Wed Jul 12 2017 - 12:35:13 EST


On Mon, Jul 10, 2017 at 12:36 PM, Moritz Fischer
<moritz.fischer@xxxxxxxxx> wrote:

>> +struct fpga_image_info *fpga_image_info_alloc(struct device *dev)
>> +{
>> + struct fpga_image_info *info;
>> +
>> + info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
>> + if (!info)
>> + return ERR_PTR(-ENOMEM);
>
> Doesn't this make it more complex? If in the end you'll anyway have to check
> if IS_ERR_OR_NULL()? As opposed to just checking if (!info) on the returned
> value.
>
> Just a thought.

Also I should save a pointer to the device in fpga_image_info so that
fpga_image_info_free() could lose the dev param. I'd add this here:

get_device(dev);
info->dev = dev;

>
>> +
>> + return info;
>> +}
>> +EXPORT_SYMBOL_GPL(fpga_image_info_alloc);
>> +
>> +void fpga_image_info_free(struct device *dev,
>> + struct fpga_image_info *info)

I'd get rid of the dev parameter.

>> +{

struct device *dev;

>> + if (!info)
>> + return;

dev = info->dev;

>> +
>> + if (info->firmware_name)
>> + devm_kfree(dev, info->firmware_name);
>> +
>> + devm_kfree(dev, info);

put_device(dev);

>> +}
>> +EXPORT_SYMBOL_GPL(fpga_image_info_free);

And fix all uses of this function to be fpga_image_info_free(info);

Alan Tull