2023-11-30 02:42:55

by Su Hui

[permalink] [raw]
Subject: [PATCH] scsi: aic7xxx: fix some problem of return value

aic7770_probe() should return negative error code rather than positive.
However, aic7770_config() only return positive error code,
ahc_linux_register_host() return both positive and negative error
code. Make aic7770_probe() return negative if error happened and let
ahc_linux_register_host() only return positive error code to fix this
problem.

ahc_linux_pci_dev_probe() should return the value of
ahc_linux_register_host() rather than zero.

Signed-off-by: Su Hui <[email protected]>
---
drivers/scsi/aic7xxx/aic7770_osm.c | 8 ++++----
drivers/scsi/aic7xxx/aic7xxx_osm.c | 2 +-
drivers/scsi/aic7xxx/aic7xxx_osm_pci.c | 4 ++--
3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/aic7xxx/aic7770_osm.c b/drivers/scsi/aic7xxx/aic7770_osm.c
index bdd177e3d762..3c1aca15d956 100644
--- a/drivers/scsi/aic7xxx/aic7770_osm.c
+++ b/drivers/scsi/aic7xxx/aic7770_osm.c
@@ -87,23 +87,23 @@ aic7770_probe(struct device *dev)
sprintf(buf, "ahc_eisa:%d", eisaBase >> 12);
name = kstrdup(buf, GFP_ATOMIC);
if (name == NULL)
- return (ENOMEM);
+ return -ENOMEM;
ahc = ahc_alloc(&aic7xxx_driver_template, name);
if (ahc == NULL)
- return (ENOMEM);
+ return -ENOMEM;
ahc->dev = dev;
error = aic7770_config(ahc, aic7770_ident_table + edev->id.driver_data,
eisaBase);
if (error != 0) {
ahc->bsh.ioport = 0;
ahc_free(ahc);
- return (error);
+ return -error;
}

dev_set_drvdata(dev, ahc);

error = ahc_linux_register_host(ahc, &aic7xxx_driver_template);
- return (error);
+ return -error;
}

static int
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
index 4ae0a1c4d374..158aaeca8941 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -1117,7 +1117,7 @@ ahc_linux_register_host(struct ahc_softc *ahc, struct scsi_host_template *templa
if (retval) {
printk(KERN_WARNING "aic7xxx: scsi_add_host failed\n");
scsi_host_put(host);
- return retval;
+ return -retval;
}

scsi_scan_host(host);
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
index a07e94fac673..e17eb8df12c4 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
@@ -241,8 +241,8 @@ ahc_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
ahc_linux_pci_inherit_flags(ahc);

pci_set_drvdata(pdev, ahc);
- ahc_linux_register_host(ahc, &aic7xxx_driver_template);
- return (0);
+ error = ahc_linux_register_host(ahc, &aic7xxx_driver_template);
+ return -error;
}

/******************************* PCI Routines *********************************/
--
2.30.2


2023-11-30 07:22:49

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] scsi: aic7xxx: fix some problem of return value

On Thu, Nov 30, 2023 at 10:41:23AM +0800, Su Hui wrote:
> ahc = ahc_alloc(&aic7xxx_driver_template, name);
> if (ahc == NULL)
> - return (ENOMEM);
> + return -ENOMEM;
> ahc->dev = dev;
> error = aic7770_config(ahc, aic7770_ident_table + edev->id.driver_data,
> eisaBase);
> if (error != 0) {
> ahc->bsh.ioport = 0;
> ahc_free(ahc);
> - return (error);
> + return -error;

aic7770_config() mostly returns positive error codes but I see it also
return -1 from ahc_reset(). So you'd want to do something like:

return error < 0 ? error : -error;



> }
>
> dev_set_drvdata(dev, ahc);
>
> error = ahc_linux_register_host(ahc, &aic7xxx_driver_template);
> - return (error);
> + return -error;
> }
>
> static int
> diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
> index 4ae0a1c4d374..158aaeca8941 100644
> --- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
> +++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
> @@ -1117,7 +1117,7 @@ ahc_linux_register_host(struct ahc_softc *ahc, struct scsi_host_template *templa
> if (retval) {
> printk(KERN_WARNING "aic7xxx: scsi_add_host failed\n");
> scsi_host_put(host);
> - return retval;
> + return -retval;

Originally ahc_linux_register_host() returned a mix of positive and
negative error codes. You have converted it to return only positive
error codes. That's good for consistency in a way, but it's a step
backwards from the big picture point of view.


> }
>
> scsi_scan_host(host);
> diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
> index a07e94fac673..e17eb8df12c4 100644
> --- a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
> +++ b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
> @@ -241,8 +241,8 @@ ahc_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
> ahc_linux_pci_inherit_flags(ahc);
>
> pci_set_drvdata(pdev, ahc);
> - ahc_linux_register_host(ahc, &aic7xxx_driver_template);
> - return (0);
> + error = ahc_linux_register_host(ahc, &aic7xxx_driver_template);
> + return -error;

This should be done in a separate patch.

patch 1: return negative error codes in ahc_linux_register_host()
patch 2: return negative error codes in aic7770_probe()
patch 3: add a check for errors in ahc_linux_pci_dev_probe()

regards,
dan carpenter

2023-12-01 01:27:19

by Su Hui

[permalink] [raw]
Subject: Re: [PATCH] scsi: aic7xxx: fix some problem of return value


On 2023/11/30 15:21, Dan Carpenter wrote:
> On Thu, Nov 30, 2023 at 10:41:23AM +0800, Su Hui wrote:
>> error = aic7770_config(ahc, aic7770_ident_table + edev->id.driver_data,
>> eisaBase);
>> if (error != 0) {
>> ahc->bsh.ioport = 0;
>> ahc_free(ahc);
>> - return (error);
>> + return -error;
> aic7770_config() mostly returns positive error codes but I see it also
> return -1 from ahc_reset(). So you'd want to do something like:
>
> return error < 0 ? error : -error;
Oh, I missed this one. Thanks for pointing out this mistake!
>> @@ -1117,7 +1117,7 @@ ahc_linux_register_host(struct ahc_softc *ahc, struct scsi_host_template *templa
>> if (retval) {
>> printk(KERN_WARNING "aic7xxx: scsi_add_host failed\n");
>> scsi_host_put(host);
>> - return retval;
>> + return -retval;
> Originally ahc_linux_register_host() returned a mix of positive and
> negative error codes. You have converted it to return only positive
> error codes. That's good for consistency in a way, but it's a step
> backwards from the big picture point of view.
Agreed, it's better to let ahc_linux_register_host() only return
negative error codes.
>> }
>>
>> scsi_scan_host(host);
>> diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
>> index a07e94fac673..e17eb8df12c4 100644
>> --- a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
>> +++ b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
>> @@ -241,8 +241,8 @@ ahc_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>> ahc_linux_pci_inherit_flags(ahc);
>>
>> pci_set_drvdata(pdev, ahc);
>> - ahc_linux_register_host(ahc, &aic7xxx_driver_template);
>> - return (0);
>> + error = ahc_linux_register_host(ahc, &aic7xxx_driver_template);
>> + return -error;
> This should be done in a separate patch.
>
> patch 1: return negative error codes in ahc_linux_register_host()
> patch 2: return negative error codes in aic7770_probe()
> patch 3: add a check for errors in ahc_linux_pci_dev_probe()

Got it, I will send v2 patch set soon.
Really thanks for your suggestions!

Su Hui