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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9ccd15b1-f751-5c05-cca0-bfccbb9d5b1f@redhat.com>
Date:   Mon, 1 Nov 2021 11:48:28 +0100
From:   Hans de Goede <hdegoede@...hat.com>
To:     Andy Shevchenko <andy.shevchenko@...il.com>
Cc:     "Rafael J . Wysocki" <rjw@...ysocki.net>,
        Mark Gross <markgross@...nel.org>,
        Andy Shevchenko <andy@...radead.org>,
        Wolfram Sang <wsa@...-dreams.de>,
        Mika Westerberg <mika.westerberg@...ux.intel.com>,
        Daniel Scally <djrscally@...il.com>,
        Laurent Pinchart <laurent.pinchart@...asonboard.com>,
        Mauro Carvalho Chehab <mchehab@...nel.org>,
        Liam Girdwood <lgirdwood@...il.com>,
        Mark Brown <broonie@...nel.org>,
        Michael Turquette <mturquette@...libre.com>,
        Stephen Boyd <sboyd@...nel.org>, Len Brown <lenb@...nel.org>,
        ACPI Devel Maling List <linux-acpi@...r.kernel.org>,
        Platform Driver <platform-driver-x86@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        linux-i2c <linux-i2c@...r.kernel.org>,
        Sakari Ailus <sakari.ailus@...ux.intel.com>,
        Kate Hsuan <hpa@...hat.com>,
        Linux Media Mailing List <linux-media@...r.kernel.org>,
        linux-clk <linux-clk@...r.kernel.org>
Subject: Re: [PATCH v4 08/11] platform/x86: int3472: Add
 get_sensor_adev_and_name() helper

Hi,

On 11/1/21 11:44, Andy Shevchenko wrote:
> On Mon, Nov 1, 2021 at 12:31 PM Hans de Goede <hdegoede@...hat.com> wrote:
>> On 10/25/21 13:31, Andy Shevchenko wrote:
>>> On Mon, Oct 25, 2021 at 12:42 PM Hans de Goede <hdegoede@...hat.com> wrote:
> 
> ...
> 
>>>> +int skl_int3472_get_sensor_adev_and_name(struct device *dev,
>>>> +                                        struct acpi_device **sensor_adev_ret,
>>>> +                                        const char **name_ret)
>>>> +{
>>>> +       struct acpi_device *adev = ACPI_COMPANION(dev);
>>>> +       struct acpi_device *sensor;
>>>> +       int ret = 0;
>>>> +
>>>> +       sensor = acpi_dev_get_first_consumer_dev(adev);
>>>> +       if (!sensor) {
>>>> +               dev_err(dev, "INT3472 seems to have no dependents.\n");
>>>> +               return -ENODEV;
>>>> +       }
>>>> +
>>>> +       *name_ret = devm_kasprintf(dev, GFP_KERNEL, I2C_DEV_NAME_FORMAT,
>>>> +                                  acpi_dev_name(sensor));
>>>> +       if (!*name_ret)
>>>> +               ret = -ENOMEM;
>>>> +
>>>> +       if (ret == 0 && sensor_adev_ret)
>>>> +               *sensor_adev_ret = sensor;
>>>> +       else
>>>> +               acpi_dev_put(sensor);
>>>> +
>>>> +       return ret;
>>>
>>> The error path is twisted a bit including far staying ret=0 assignment.
>>>
>>> Can it be
>>>
>>>        int ret;
>>>        ...
>>>        *name_ret = devm_kasprintf(dev, GFP_KERNEL, I2C_DEV_NAME_FORMAT,
>>>                                   acpi_dev_name(sensor));
>>>        if (!*name_ret) {
>>>                acpi_dev_put(sensor);
>>>                return -ENOMEM;
>>>        }
>>>
>>>        if (sensor_adev_ret)
>>>                *sensor_adev_ret = sensor;
>>>
>>>        return 0;
>>>
>>> ?
>>
>> That misses an acpi_dev_put(sensor) when sensor_adev_ret == NULL.
> 
> else
>   acpi_dev_put(...);

Then we have 2 acpi_dev_put() paths, IMHO the original code
which clearly states that we keep the ref:

if (success && returning-the-ref)

and put the ref in all other cases is better then having
2 separate put paths.

Regards,

Hans

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ