[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5d96daca.1c69fb81.fe5e4.e623@mx.google.com>
Date: Thu, 03 Oct 2019 22:38:17 -0700
From: Stephen Boyd <swboyd@...omium.org>
To: Murali Nalajala <mnalajal@...eaurora.org>,
gregkh@...uxfoundation.org, rafael@...nel.org
Cc: mnalajal@...eaurora.org, linux-arm-msm@...r.kernel.org,
linux-kernel@...r.kernel.org, bjorn.andersson@...aro.org
Subject: Re: [PATCH v1] base: soc: Handle custom soc information sysfs entries
Quoting Murali Nalajala (2019-10-03 16:51:50)
> @@ -151,14 +156,16 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr
>
> ret = device_register(&soc_dev->dev);
> if (ret)
> - goto out3;
> + goto out4;
>
> return soc_dev;
>
> -out3:
> +out4:
> ida_simple_remove(&soc_ida, soc_dev->soc_dev_num);
> put_device(&soc_dev->dev);
> soc_dev = NULL;
> +out3:
> + kfree(soc_attr_groups);
This code is tricky. put_device(&soc_dev->dev) will call soc_release()
so we set soc_dev to NULL before calling kfree() on the error path. This
way we don't doubly free a pointer that the release function will take
care of. I wonder if the release function could free the ida as well,
and then we could just make the device_register() failure path call
put_device() and return ERR_PTR(ret) directly. Then the error path is
simpler because we can avoid changing two pointers to NULL to avoid the
double free twice. Or just inline the ida remove and put_device() call
in the if and then goto out1 to consolidate the error pointer
conversion.
> out2:
> kfree(soc_dev);
> out1:
Powered by blists - more mailing lists