Re: [PATCH] w1: Add 1-wire slave device driver for DS28E04-100

From: Andrew Morton
Date: Thu May 10 2012 - 19:22:24 EST


On Fri, 11 May 2012 00:57:58 +0200
Markus Franke <markus.franke@xxxxxxxxxxxxxxxxxxxx> wrote:

> +static int w1_f1C_add_slave(struct w1_slave *sl)
> +{
> + int err = 0;
> + int i;
> + struct w1_f1C_data *data = NULL;
> +
> + if (w1_enable_crccheck) {
> + data = kzalloc(sizeof(struct w1_f1C_data), GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> + sl->family_data = data;
> + }
> +
> + /* create binary sysfs attributes */
> + for (i = 0; i < NB_SYSFS_BIN_FILES && !err; ++i)
> + err = sysfs_create_bin_file(
> + &sl->dev.kobj, &(w1_f1C_bin_attr[i]));
> +
> + if (err)
> + goto out;

If this goto is taken, we will leak 0..i sysfs files.

> + /* create device attributes */
> + err = device_create_file(&sl->dev, &dev_attr_crccheck);
> +
> + if (err) {
> + /* remove binary sysfs attributes */
> + for (i = 0; i < NB_SYSFS_BIN_FILES; ++i)
> + sysfs_remove_bin_file(
> + &sl->dev.kobj, &(w1_f1C_bin_attr[i]));
> + }
> +
> +out:
> + if (err) {
> + if (w1_enable_crccheck)
> + kfree(data);

kfree(NULL) is legal - the w1_enable_crccheck test can be removed.

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