pata_ali: check the pci_get_device failure
diff mbox series

Message ID 20190725012506.17831-1-navid.emamdoost@gmail.com
State New
Headers show
Series
  • pata_ali: check the pci_get_device failure
Related show

Commit Message

Navid Emamdoost July 25, 2019, 1:25 a.m. UTC
pci_get_device may fail and return NULL. This eventually will be
dereferenced in __pci_register_driver. So null check is necessary.

Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
 drivers/ata/pata_ali.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Bartlomiej Zolnierkiewicz July 26, 2019, 10:32 a.m. UTC | #1
Hi,

On 7/25/19 3:25 AM, Navid Emamdoost wrote:
> pci_get_device may fail and return NULL. This eventually will be
> dereferenced in __pci_register_driver. So null check is necessary.

I'm sorry to say this but the patch is incorrect and should not be
applied.

ALI M1533 ISA bridge presence is optional (the driver can work also
with other ISA bridges) and ali_isa_bridge is always correctly checked
for NULL before being dereferenced in the driver.

> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---
>  drivers/ata/pata_ali.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
> index 0b122f903b8a..47d9bec1f2e2 100644
> --- a/drivers/ata/pata_ali.c
> +++ b/drivers/ata/pata_ali.c
> @@ -627,6 +627,8 @@ static int __init ali_init(void)
>  {
>  	int ret;
>  	ali_isa_bridge = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
> +	if (!ali_isa_bridge)
> +		return -EINVAL;
>  
>  	ret = pci_register_driver(&ali_pci_driver);
>  	if (ret < 0)

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics

Patch
diff mbox series

diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
index 0b122f903b8a..47d9bec1f2e2 100644
--- a/drivers/ata/pata_ali.c
+++ b/drivers/ata/pata_ali.c
@@ -627,6 +627,8 @@  static int __init ali_init(void)
 {
 	int ret;
 	ali_isa_bridge = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
+	if (!ali_isa_bridge)
+		return -EINVAL;
 
 	ret = pci_register_driver(&ali_pci_driver);
 	if (ret < 0)