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]
Date:	Mon, 10 Sep 2012 14:44:32 -0600
From:	Bjorn Helgaas <bhelgaas@...gle.com>
To:	Jiri Slaby <jslaby@...e.cz>
Cc:	linux-pci@...r.kernel.org, linux-kernel@...r.kernel.org,
	jirislaby@...il.com, Feng Tang <feng.tang@...el.com>,
	Fengguang Wu <fengguang.wu@...el.com>
Subject: Re: [PATCH 1/1] PCI: fix on-stack pci_device_id's

On Mon, Sep 10, 2012 at 1:36 PM, Jiri Slaby <jslaby@...e.cz> wrote:
> Commit "PCI: Use pci_device_id on stack for pci_get_subsys/class() to
> avoid kmalloc" changed heap allocations to on-stack variables, but it
> did not add initialization of other than set members. This causes
> random failures during bootup wherever pci device is needed to be
> found. Hence the boot just hangs or panics.
>
> This patches fixes it by setting the content of pci_device_id directly
> in the initializer.

Nice!  I fixed this already by adding a memset(), but I like your way
better.  I knew we could initialize members of a structure on the
stack, but I didn't know C guaranteed that uninitialized members would
be implicitly initialized also.  But apparently it does:

http://stackoverflow.com/questions/10828294/c-and-c-partial-initialization-of-automatic-structure

> Signed-off-by: Jiri Slaby <jslaby@...e.cz>
> Cc: Feng Tang <feng.tang@...el.com>
> Cc: Bjorn Helgaas <bhelgaas@...gle.com>
> Cc: Fengguang Wu <fengguang.wu@...el.com>
> ---
>  drivers/pci/search.c | 25 ++++++++++++++-----------
>  1 file changed, 14 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/pci/search.c b/drivers/pci/search.c
> index 00d486a..bf969ba 100644
> --- a/drivers/pci/search.c
> +++ b/drivers/pci/search.c
> @@ -243,12 +243,12 @@ struct pci_dev *pci_get_subsys(unsigned int vendor, unsigned int device,
>                                unsigned int ss_vendor, unsigned int ss_device,
>                                struct pci_dev *from)
>  {
> -       struct pci_device_id id;
> -
> -       id.vendor = vendor;
> -       id.device = device;
> -       id.subvendor = ss_vendor;
> -       id.subdevice = ss_device;
> +       struct pci_device_id id = {
> +               .vendor = vendor,
> +               .device = device,
> +               .subvendor = ss_vendor,
> +               .subdevice = ss_device,
> +       };
>
>         return pci_get_dev_by_id(&id, from);
>  }
> @@ -289,11 +289,14 @@ pci_get_device(unsigned int vendor, unsigned int device, struct pci_dev *from)
>   */
>  struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from)
>  {
> -       struct pci_device_id id;
> -
> -       id.vendor = id.device = id.subvendor = id.subdevice = PCI_ANY_ID;
> -       id.class_mask = PCI_ANY_ID;
> -       id.class = class;
> +       struct pci_device_id id = {
> +               .vendor = PCI_ANY_ID,
> +               .device = PCI_ANY_ID,
> +               .subvendor = PCI_ANY_ID,
> +               .subdevice = PCI_ANY_ID,
> +               .class_mask = PCI_ANY_ID,
> +               .class = class,
> +       };
>
>         return pci_get_dev_by_id(&id, from);
>  }
> --
> 1.7.11.5
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ