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

Andrew Morton
2012-05-10T23:22:29Z

On Fri, 11 May 2012 00:57:58 +0200
Markus Franke <markus.franke@s2002.tu-chemnitz.de> 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;
> +}