Re: [PATCH 3/4] of: changesets: Introduce changeset helper methods

From: Rob Herring
Date: Mon May 09 2016 - 11:08:36 EST


On Mon, May 9, 2016 at 9:34 AM, Pantelis Antoniou
<pantelis.antoniou@xxxxxxxxxxxx> wrote:
> Hi Rob,
>
>> On May 9, 2016, at 17:27 , Rob Herring <robherring2@xxxxxxxxx> wrote:
>>
>> On Mon, May 9, 2016 at 8:20 AM, Pantelis Antoniou
>> <pantelis.antoniou@xxxxxxxxxxxx> wrote:
>>> Changesets are very powerful, but the lack of a helper API
>>> makes using them cumbersome. Introduce a simple copy based
>>> API that makes things considerably easier.

[...]

>>> + /*
>>> + * NOTE: There is no check for zero length value.
>>> + * In case of a boolean property, this will allocate a value
>>> + * of zero bytes. We do this to work around the use
>>> + * of of_get_property() calls on boolean values.
>>> + */
>>> + new_value = kmemdup(value, length, GFP_KERNEL);
>>> + if (!new_value)
>>> + goto out_no_value;
>>> +
>>> + of_property_set_flag(prop, OF_DYNAMIC);
>>> +
>>> + prop->name = new_name;
>>> + prop->value = new_value;
>>> + prop->length = length;
>>> +
>>> + if (!update)
>>> + ret = of_changeset_add_property(ocs, np, prop);
>>> + else
>>> + ret = of_changeset_update_property(ocs, np, prop);
>>> +
>>> + if (ret != 0)
>>
>> if (!ret)
>> return 0;
>>
>>
>
>>> + goto out_no_add;
>>> +
>>> + return 0;
>>> +
>>> +out_no_add:
>>
>> ... and remove all this.
>>
>
> Err, thereâs an exit path here from kmemdup (goto err_no_value).
> Weâll be leaking memory on error.

No you won't. "This" is the hunk above it. The error handling would
still be here:

>>> + kfree(prop->value);
>>> +out_no_value:
>>> + kfree(prop->name);
>>> +out_no_name:
>>> + kfree(prop);
>>> +out_no_prop:
>>> + return ret;
>>> +}