Skip to contentSkip to conversation

scsi: mptfusion: Remove unnecessary parentheses and simplify null checks

PATCH Applied Nathan Chancellor 4 participants 6 messages Sep 15, 2018 – Oct 11, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: mptfusion: Remove unnecessary parentheses and simplify null checks

Clang warns when multiple pairs of parentheses are used for a single conditional statement.

drivers/message/fusion/mptbase.c:338:11: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]

        if ((ioc == NULL))
             ~~~~^~~~~~~

drivers/message/fusion/mptbase.c:338:11: note: remove extraneous parentheses around the comparison to silence this warning
if ((ioc == NULL))
~ ^ ~
drivers/message/fusion/mptbase.c:338:11: note: use '=' to turn this equality comparison into an assignment

        if ((ioc == NULL))
                 ^~
                 =
drivers/message/fusion/mptbase.c:342:12: warning: equality comparison
with extraneous parentheses [-Wparentheses-equality]
        if ((pdev == NULL))
             ~~~~~^~~~~~~

drivers/message/fusion/mptbase.c:342:12: note: remove extraneous parentheses around the comparison to silence this warning
if ((pdev == NULL))
~ ^ ~
drivers/message/fusion/mptbase.c:342:12: note: use '=' to turn this equality comparison into an assignment

        if ((pdev == NULL))
                  ^~
                  =

2 warnings generated.

Remove them and while we're at it, simplify the NULL checks as '!var' is used more than 'var == NULL'.

---
 drivers/message/fusion/mptbase.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/message/fusion/mptbase.c +2 -2
index dc1e43a02599..ba551d8dfba4 100644
@@ -335,11 +335,11 @@ static int mpt_remove_dead_ioc_func(void *arg)
 	MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
 	struct pci_dev *pdev;
 
-	if ((ioc == NULL))
+	if (!ioc)
 		return -1;
 
 	pdev = ioc->pcidev;
-	if ((pdev == NULL))
+	if (!pdev)
 		return -1;
 
 	pci_stop_and_remove_bus_device_locked(pdev);
Signature · 1 line
2.18.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 30 lines · Nathan Chancellor

Clang warns when multiple pairs of parentheses are used for a single conditional statement.

drivers/message/fusion/mptbase.c:338:11: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]

        if ((ioc == NULL))
             ~~~~^~~~~~~

drivers/message/fusion/mptbase.c:338:11: note: remove extraneous parentheses around the comparison to silence this warning
if ((ioc == NULL))
~ ^ ~
drivers/message/fusion/mptbase.c:338:11: note: use '=' to turn this equality comparison into an assignment

        if ((ioc == NULL))
                 ^~
                 =
drivers/message/fusion/mptbase.c:342:12: warning: equality comparison
with extraneous parentheses [-Wparentheses-equality]
        if ((pdev == NULL))
             ~~~~~^~~~~~~

drivers/message/fusion/mptbase.c:342:12: note: remove extraneous parentheses around the comparison to silence this warning
if ((pdev == NULL))
~ ^ ~
drivers/message/fusion/mptbase.c:342:12: note: use '=' to turn this equality comparison into an assignment

        if ((pdev == NULL))
                  ^~
                  =
Quoted 7 lines

2 warnings generated.

Remove them and while we're at it, simplify the NULL checks as '!var' is used more than 'var == NULL'.

Nathan,
Thanks for this patch.

Quoted 25 lines
---
 drivers/message/fusion/mptbase.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/message/fusion/mptbase.c +2 -3
index dc1e43a02599..ba551d8dfba4 100644
@@ -335,11 +335,11 @@ static int mpt_remove_dead_ioc_func(void *arg)
        MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
        struct pci_dev *pdev;
 
-       if ((ioc == NULL))
+       if (!ioc)
                return -1;
 
        pdev = ioc->pcidev;
-       if ((pdev == NULL))
+       if (!pdev)
                return -1;
 
        pci_stop_and_remove_bus_device_locked(pdev);
--

2.18.0

Signature · 2 lines
Thanks,
~Nick Desaulniers
#2 lore raw
In reply to Nathan Chancellor

Nathan,

Quoted 2 lines

Clang warns when multiple pairs of parentheses are used for a single conditional statement.

Applied to 4.20/scsi-queue. Thank you!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#3 lore raw
In reply to Nathan Chancellor
Quoted 15 lines · Nathan Chancellor
---
 drivers/message/fusion/mptbase.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/message/fusion/mptbase.c +0 -1
index dc1e43a02599..ba551d8dfba4 100644
@@ -335,11 +335,11 @@ static int mpt_remove_dead_ioc_func(void *arg)
        MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
        struct pci_dev *pdev;
 
-       if ((ioc == NULL))

drivers/message/fusion/mptbase.c static int mpt_remove_dead_ioc_func(void *arg)

Quoted 10 lines
drivers/message/fusion/mptbase.c +2 -2
+       if (!ioc)
                return -1;
 
        pdev = ioc->pcidev;
-       if ((pdev == NULL))
+       if (!pdev)
                return -1;
 
        pci_stop_and_remove_bus_device_locked(pdev);
--

The exact same code also exists in drivers/scsi/mpt3sas/. I had a similar patch for both drivers, but saw that yours now got merged for fusion.

If you don't mind, could you fix mpt3sas_base.c the same way?

Arnd

#4 lore raw
Quoted 33 lines · Arnd Bergmann
Quoted 15 lines · Nathan Chancellor
---
 drivers/message/fusion/mptbase.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/message/fusion/mptbase.c +0 -1
index dc1e43a02599..ba551d8dfba4 100644
@@ -335,11 +335,11 @@ static int mpt_remove_dead_ioc_func(void *arg)
        MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
        struct pci_dev *pdev;
 
-       if ((ioc == NULL))

drivers/message/fusion/mptbase.c static int mpt_remove_dead_ioc_func(void *arg)

Quoted 10 lines
drivers/message/fusion/mptbase.c +2 -2
+       if (!ioc)
                return -1;
 
        pdev = ioc->pcidev;
-       if ((pdev == NULL))
+       if (!pdev)
                return -1;
 
        pci_stop_and_remove_bus_device_locked(pdev);
--

The exact same code also exists in drivers/scsi/mpt3sas/. I had a similar patch for both drivers, but saw that yours now got merged for fusion.

Quoted 3 lines

If you don't mind, could you fix mpt3sas_base.c the same way?

Arnd

Hi Arnd,

I did sent a patch for this a little bit later: https://lore.kernel.org/lkml/[email protected]/

I am still waiting for it to be merged.

Thanks!
Nathan

#5 lore raw

Nathan,

Quoted 5 lines
Quoted 5 lines

The exact same code also exists in drivers/scsi/mpt3sas/. I had a similar patch for both drivers, but saw that yours now got merged for fusion.

If you don't mind, could you fix mpt3sas_base.c the same way?

Quoted 8 lines
Quoted 1 line

Arnd

Hi Arnd,

I did sent a patch for this a little bit later:
https://lore.kernel.org/lkml/[email protected]/

I am still waiting for it to be merged.

I generally don't merge patches for drivers that are actively maintained unless the driver maintainer explicitly acks the change. However, this was trivial enough. Applied to 4.20/scsi-queue.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering