linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: qla2xxx: Simplify conditional check
@ 2019-03-20 16:33 Nathan Chancellor
  2019-03-20 17:08 ` Nick Desaulniers
  2019-03-26 22:04 ` [PATCH v2] scsi: qla2xxx: Simplify conditional check again Nathan Chancellor
  0 siblings, 2 replies; 5+ messages in thread
From: Nathan Chancellor @ 2019-03-20 16:33 UTC (permalink / raw)
  To: qla2xxx-upstream, James E.J. Bottomley, Martin K. Petersen
  Cc: linux-scsi, linux-kernel, clang-built-linux, Nathan Chancellor

Clang generates a warning when it sees a logical not followed by a
conditional operator like ==, >, or < because it thinks that the logical
not should be applied to the whole statement:

drivers/scsi/qla2xxx/qla_nx.c:3702:7: warning: logical not is only
applied to the left hand side of this comparison
[-Wlogical-not-parentheses]
                if (!qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
                    ^
drivers/scsi/qla2xxx/qla_nx.c:3702:7: note: add parentheses after the
'!' to evaluate the comparison first
                if (!qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
                    ^
                     (
drivers/scsi/qla2xxx/qla_nx.c:3702:7: note: add parentheses around left
hand side expression to silence this warning
                if (!qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
                    ^
                    (
1 warning generated.

It assumes the author might have made a mistake in their logic:

if (!a == b) -> if (!(a == b))

Sometimes that is the case; other times, it's just a super convoluted
way of saying 'if (a)' when b = 0:

if (!1 == 0) -> if (0 == 0) -> if (true)

Alternatively:

if (!1 == 0) -> if (!!1) -> if (1)

Simplify this comparison so that Clang doesn't complain.

Link: https://github.com/ClangBuiltLinux/linux/issues/80
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---

This is commit 0bfe7d3cae58 ("scsi: qla2xxx: Simplify conditional check")
upstream but commit 3695310e37b4 ("scsi: qla2xxx: Update flash
read/write routine") in the 5.2/scsi-queue branch silently reverted it.
I don't care if it is squashed or not, I just want the warning to stay
fixed.

Thanks,
Nathan

 drivers/scsi/qla2xxx/qla_nx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_nx.c b/drivers/scsi/qla2xxx/qla_nx.c
index de2bc78449e7..121e18b3b9f8 100644
--- a/drivers/scsi/qla2xxx/qla_nx.c
+++ b/drivers/scsi/qla2xxx/qla_nx.c
@@ -3699,8 +3699,8 @@ qla82xx_chip_reset_cleanup(scsi_qla_host_t *vha)
 		spin_unlock_irqrestore(&ha->hardware_lock, flags);
 
 		/* Wait for pending cmds (physical and virtual) to complete */
-		if (!qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
-		    WAIT_HOST) == QLA_SUCCESS) {
+		if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
+		    WAIT_HOST)) {
 			ql_dbg(ql_dbg_init, vha, 0x00b3,
 			    "Done wait for "
 			    "pending commands.\n");
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi: qla2xxx: Simplify conditional check
  2019-03-20 16:33 [PATCH] scsi: qla2xxx: Simplify conditional check Nathan Chancellor
@ 2019-03-20 17:08 ` Nick Desaulniers
  2019-03-26 22:04 ` [PATCH v2] scsi: qla2xxx: Simplify conditional check again Nathan Chancellor
  1 sibling, 0 replies; 5+ messages in thread
From: Nick Desaulniers @ 2019-03-20 17:08 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: qla2xxx-upstream, James E.J. Bottomley, Martin K. Petersen,
	linux-scsi, LKML, clang-built-linux

On Wed, Mar 20, 2019 at 9:36 AM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> Clang generates a warning when it sees a logical not followed by a
> conditional operator like ==, >, or < because it thinks that the logical
> not should be applied to the whole statement:
>
> drivers/scsi/qla2xxx/qla_nx.c:3702:7: warning: logical not is only
> applied to the left hand side of this comparison
> [-Wlogical-not-parentheses]
>                 if (!qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
>                     ^
> drivers/scsi/qla2xxx/qla_nx.c:3702:7: note: add parentheses after the
> '!' to evaluate the comparison first
>                 if (!qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
>                     ^
>                      (
> drivers/scsi/qla2xxx/qla_nx.c:3702:7: note: add parentheses around left
> hand side expression to silence this warning
>                 if (!qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
>                     ^
>                     (
> 1 warning generated.
>
> It assumes the author might have made a mistake in their logic:
>
> if (!a == b) -> if (!(a == b))
>
> Sometimes that is the case; other times, it's just a super convoluted
> way of saying 'if (a)' when b = 0:
>
> if (!1 == 0) -> if (0 == 0) -> if (true)
>
> Alternatively:
>
> if (!1 == 0) -> if (!!1) -> if (1)
>
> Simplify this comparison so that Clang doesn't complain.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/80
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> ---
>
> This is commit 0bfe7d3cae58 ("scsi: qla2xxx: Simplify conditional check")
> upstream but commit 3695310e37b4 ("scsi: qla2xxx: Update flash
> read/write routine") in the 5.2/scsi-queue branch silently reverted it.
> I don't care if it is squashed or not, I just want the warning to stay
> fixed.

This is probably a simpler commit message. A "Fixes:" tag is a simple
enough addition, too.
Thanks for catching this and resending the fix.

>
> Thanks,
> Nathan
>
>  drivers/scsi/qla2xxx/qla_nx.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/qla2xxx/qla_nx.c b/drivers/scsi/qla2xxx/qla_nx.c
> index de2bc78449e7..121e18b3b9f8 100644
> --- a/drivers/scsi/qla2xxx/qla_nx.c
> +++ b/drivers/scsi/qla2xxx/qla_nx.c
> @@ -3699,8 +3699,8 @@ qla82xx_chip_reset_cleanup(scsi_qla_host_t *vha)
>                 spin_unlock_irqrestore(&ha->hardware_lock, flags);
>
>                 /* Wait for pending cmds (physical and virtual) to complete */
> -               if (!qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
> -                   WAIT_HOST) == QLA_SUCCESS) {
> +               if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
> +                   WAIT_HOST)) {
>                         ql_dbg(ql_dbg_init, vha, 0x00b3,
>                             "Done wait for "
>                             "pending commands.\n");
> --
> 2.21.0
>
> --
> You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com.
> To post to this group, send email to clang-built-linux@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20190320163315.12740-1-natechancellor%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.



-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] scsi: qla2xxx: Simplify conditional check again
  2019-03-20 16:33 [PATCH] scsi: qla2xxx: Simplify conditional check Nathan Chancellor
  2019-03-20 17:08 ` Nick Desaulniers
@ 2019-03-26 22:04 ` Nathan Chancellor
  2019-03-27 17:01   ` Nick Desaulniers
  2019-03-28  1:28   ` Martin K. Petersen
  1 sibling, 2 replies; 5+ messages in thread
From: Nathan Chancellor @ 2019-03-26 22:04 UTC (permalink / raw)
  To: James E.J. Bottomley, Martin K. Petersen, Joe Carnuccio,
	Himanshu Madhani, qla2xxx-upstream
  Cc: linux-scsi, linux-kernel, Nick Desaulniers, clang-built-linux,
	Nathan Chancellor

Clang warns when it sees a logical not on the left side of a
conditional statement because it thinks the logical not should
be applied to the whole statement, not just the left side:

drivers/scsi/qla2xxx/qla_nx.c:3703:7: warning: logical not is only
applied to the left hand side of this comparison
[-Wlogical-not-parentheses]

This particular instance was already fixed by commit 0bfe7d3cae58 ("scsi:
qla2xxx: Simplify conditional check") upstream but it was reintroduced
by commit 3695310e37b4 ("scsi: qla2xxx: Update flash read/write
routine") in the 5.2/scsi-queue.

Fixes: 3695310e37b4 ("scsi: qla2xxx: Update flash read/write routine")
Link: https://github.com/ClangBuiltLinux/linux/issues/80
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---

v1 -> v2:

* Reword commit message so make it clear this is just a reapplication of
  a commit that is already in mainline, as suggested by Nick.

* Include the authors who reintroduced this warning.

 drivers/scsi/qla2xxx/qla_nx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_nx.c b/drivers/scsi/qla2xxx/qla_nx.c
index e0b4387fd6ba..359ebb634d96 100644
--- a/drivers/scsi/qla2xxx/qla_nx.c
+++ b/drivers/scsi/qla2xxx/qla_nx.c
@@ -3700,8 +3700,8 @@ qla82xx_chip_reset_cleanup(scsi_qla_host_t *vha)
 		spin_unlock_irqrestore(&ha->hardware_lock, flags);
 
 		/* Wait for pending cmds (physical and virtual) to complete */
-		if (!qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
-		    WAIT_HOST) == QLA_SUCCESS) {
+		if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
+		    WAIT_HOST)) {
 			ql_dbg(ql_dbg_init, vha, 0x00b3,
 			    "Done wait for "
 			    "pending commands.\n");
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] scsi: qla2xxx: Simplify conditional check again
  2019-03-26 22:04 ` [PATCH v2] scsi: qla2xxx: Simplify conditional check again Nathan Chancellor
@ 2019-03-27 17:01   ` Nick Desaulniers
  2019-03-28  1:28   ` Martin K. Petersen
  1 sibling, 0 replies; 5+ messages in thread
From: Nick Desaulniers @ 2019-03-27 17:01 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: James E.J. Bottomley, Martin K. Petersen, Joe Carnuccio,
	Himanshu Madhani, qla2xxx-upstream, linux-scsi, LKML,
	clang-built-linux

On Tue, Mar 26, 2019 at 3:06 PM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> Clang warns when it sees a logical not on the left side of a
> conditional statement because it thinks the logical not should
> be applied to the whole statement, not just the left side:
>
> drivers/scsi/qla2xxx/qla_nx.c:3703:7: warning: logical not is only
> applied to the left hand side of this comparison
> [-Wlogical-not-parentheses]
>
> This particular instance was already fixed by commit 0bfe7d3cae58 ("scsi:
> qla2xxx: Simplify conditional check") upstream but it was reintroduced
> by commit 3695310e37b4 ("scsi: qla2xxx: Update flash read/write
> routine") in the 5.2/scsi-queue.

Nathan, thanks for following up and rewording the commit message to
clearly state how we got here.
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

>
> Fixes: 3695310e37b4 ("scsi: qla2xxx: Update flash read/write routine")
> Link: https://github.com/ClangBuiltLinux/linux/issues/80
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> ---
>
> v1 -> v2:
>
> * Reword commit message so make it clear this is just a reapplication of
>   a commit that is already in mainline, as suggested by Nick.
>
> * Include the authors who reintroduced this warning.
>
>  drivers/scsi/qla2xxx/qla_nx.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/qla2xxx/qla_nx.c b/drivers/scsi/qla2xxx/qla_nx.c
> index e0b4387fd6ba..359ebb634d96 100644
> --- a/drivers/scsi/qla2xxx/qla_nx.c
> +++ b/drivers/scsi/qla2xxx/qla_nx.c
> @@ -3700,8 +3700,8 @@ qla82xx_chip_reset_cleanup(scsi_qla_host_t *vha)
>                 spin_unlock_irqrestore(&ha->hardware_lock, flags);
>
>                 /* Wait for pending cmds (physical and virtual) to complete */
> -               if (!qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
> -                   WAIT_HOST) == QLA_SUCCESS) {
> +               if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
> +                   WAIT_HOST)) {
>                         ql_dbg(ql_dbg_init, vha, 0x00b3,
>                             "Done wait for "
>                             "pending commands.\n");
> --
> 2.21.0
>


-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] scsi: qla2xxx: Simplify conditional check again
  2019-03-26 22:04 ` [PATCH v2] scsi: qla2xxx: Simplify conditional check again Nathan Chancellor
  2019-03-27 17:01   ` Nick Desaulniers
@ 2019-03-28  1:28   ` Martin K. Petersen
  1 sibling, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2019-03-28  1:28 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: James E.J. Bottomley, Martin K. Petersen, Joe Carnuccio,
	Himanshu Madhani, qla2xxx-upstream, linux-scsi, linux-kernel,
	Nick Desaulniers, clang-built-linux


Nathan,

> Clang warns when it sees a logical not on the left side of a
> conditional statement because it thinks the logical not should be
> applied to the whole statement, not just the left side:

Applied to 5.2/scsi-queue, thanks.

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-03-28  1:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-20 16:33 [PATCH] scsi: qla2xxx: Simplify conditional check Nathan Chancellor
2019-03-20 17:08 ` Nick Desaulniers
2019-03-26 22:04 ` [PATCH v2] scsi: qla2xxx: Simplify conditional check again Nathan Chancellor
2019-03-27 17:01   ` Nick Desaulniers
2019-03-28  1:28   ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).