lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 16 Apr 2012 14:35:40 -0700
From:	"Turquette, Mike" <mturquette@...com>
To:	Sascha Hauer <s.hauer@...gutronix.de>
Cc:	Andrew Lunn <andrew@...n.ch>,
	Mark Brown <broonie@...nsource.wolfsonmicro.com>,
	Russell King <linux@....linux.org.uk>, patches@...aro.org,
	Rajendra Nayak <rnayak@...com>, linux-kernel@...r.kernel.org,
	Saravana Kannan <skannan@...eaurora.org>,
	linux-arm-kernel@...ts.infradead.org,
	Olof Johansson <olof@...om.net>, linaro-dev@...ts.linaro.org,
	arnd.bergmann@...aro.org, Richard Zhao <richard.zhao@...aro.org>,
	Shawn Guo <shawn.guo@...escale.com>
Subject: Re: [PATCH 12/13] clk: core: copy parent_names & return error codes

On Mon, Apr 16, 2012 at 1:30 PM, Sascha Hauer <s.hauer@...gutronix.de> wrote:
> On Wed, Apr 11, 2012 at 06:02:50PM -0700, Mike Turquette wrote:
>>  struct clk *clk_register(struct device *dev, const char *name,
>>               const struct clk_ops *ops, struct clk_hw *hw,
>>               const char **parent_names, u8 num_parents, unsigned long flags)
>>  {
>> +     int i, ret = -ENOMEM;
>
> I suggest to move the initialization of ret from here...
>
>>       struct clk *clk;
>>
>>       clk = kzalloc(sizeof(*clk), GFP_KERNEL);
>> -     if (!clk)
>> -             return NULL;
>> +     if (!clk) {
>> +             pr_err("%s: could not allocate clk\n", __func__);
>> +             goto fail_out;
>> +     }
>>
>>       clk->name = name;
>>       clk->ops = ops;
>>       clk->hw = hw;
>>       clk->flags = flags;
>> -     clk->parent_names = parent_names;
>>       clk->num_parents = num_parents;
>>       hw->clk = clk;
>>
>> -     __clk_init(dev, clk);
>> +     /* allocate local copy in case parent_names is __initdata */
>> +     clk->parent_names = kzalloc((sizeof(char*) * num_parents),
>> +                     GFP_KERNEL);
>> +
>> +     if (!clk->parent_names) {
>> +             pr_err("%s: could not allocate clk->parent_names\n", __func__);
>> +             goto fail_parent_names;
>> +     }
>> +
>> +     /* copy each string name in case parent_names is __initdata */
>
> ... to here.
>
> The rationale is that when this code is changed later someone might use
> ret above and doesn't remember that the code below expects ret to be
> initialized with -ENOMEM. Also it's easier to see that the code is
> correct.

That is sensible.

Thanks,
Mike

> Sascha
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ