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]
Message-ID: <d6cbd8d362ae84dde2ccde6698be0d3c@linux.dev>
Date:   Fri, 27 Aug 2021 02:39:23 +0000
From:   yajun.deng@...ux.dev
To:     "Rob Herring" <robh@...nel.org>
Cc:     "Bjorn Helgaas" <bhelgaas@...gle.com>,
        "Arnd Bergmann" <arnd@...db.de>,
        "Lorenzo Pieralisi" <lorenzo.pieralisi@....com>,
        "PCI" <linux-pci@...r.kernel.org>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH linux-next] PCI: Fix the order in unregister path

August 26, 2021 8:01 PM, "Rob Herring" <robh@...nel.org> wrote:

> On Wed, Aug 25, 2021 at 10:57 PM <yajun.deng@...ux.dev> wrote:
> 
>> August 25, 2021 9:55 PM, "Rob Herring" <robh@...nel.org> wrote:
>> 
>> On Wed, Aug 25, 2021 at 3:34 AM Yajun Deng <yajun.deng@...ux.dev> wrote:
>> 
>> device_del() should be called first and then called put_device() in
>> unregister path, becase if that the final reference count, the device
>> will be cleaned up via device_release() above. So use device_unregister()
>> instead.
>> 
>> Fixes: 9885440b16b8 (PCI: Fix pci_host_bridge struct device release/free handling)
>> Signed-off-by: Yajun Deng <yajun.deng@...ux.dev>
>> ---
>> drivers/pci/probe.c | 4 +---
>> 1 file changed, 1 insertion(+), 3 deletions(-)
>> 
>> NAK.
>> 
>> The current code is correct. Go read the comments for device_add/device_del.
>> 
>> But the device_unregister() is only contains device_del() and put_device(). It just put
>> device_del() before put_device().
> 
> And that is the wrong order as we want to undo what the code above
> did. The put_device here is for the get_device we did. The put_device
> in device_unregister is for the get_device that device_register did
> (on success only).
> 
> Logically, it is wrong too to call unregister if register failed. That
> would be like doing this:
> 
> p = malloc(1);
> if (!p)
> free(p);
>
This is the raw code:
        err = device_register(&bus->dev);
        if (err)
                goto unregister;
unregister:
        put_device(&bridge->dev);
        device_del(&bridge->dev);

This is my code:
        err = device_register(&bus->dev);
        if (err)
                goto unregister;
 unregister:
        device_unregister(&bridge->dev);


The parameter in  device_register() is bus->dev, but the parameter in device_unregister() is bridge->dev.The are different.
The bridge->dev is already success before called device_register().So it wouldn't be happen like your code.

 
> Rob

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ