diff mbox series

isdn: isdnloop: fix pointer dereference bug

Message ID 20190307093241.3380715-1-arnd@arndb.de
State Accepted
Delegated to: David Miller
Headers show
Series isdn: isdnloop: fix pointer dereference bug | expand

Commit Message

Arnd Bergmann March 7, 2019, 9:32 a.m. UTC
clang has spotted an ancient code bug and warns about it with:

drivers/isdn/isdnloop/isdnloop.c:573:12: error: address of array 'card->rcard' will always evaluate to 'true' [-Werror,-Wpointer-bool-conversion]

This is an array of pointers, so we should check if a specific
pointer exists in the array before using it, not whether the
array itself exists.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/isdn/isdnloop/isdnloop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Nathan Chancellor March 7, 2019, 3:17 p.m. UTC | #1
On Thu, Mar 07, 2019 at 10:32:07AM +0100, Arnd Bergmann wrote:
> clang has spotted an ancient code bug and warns about it with:
> 
> drivers/isdn/isdnloop/isdnloop.c:573:12: error: address of array 'card->rcard' will always evaluate to 'true' [-Werror,-Wpointer-bool-conversion]
> 
> This is an array of pointers, so we should check if a specific
> pointer exists in the array before using it, not whether the
> array itself exists.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>

> ---
>  drivers/isdn/isdnloop/isdnloop.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/isdn/isdnloop/isdnloop.c b/drivers/isdn/isdnloop/isdnloop.c
> index f4253d468ae1..755c6bbc9553 100644
> --- a/drivers/isdn/isdnloop/isdnloop.c
> +++ b/drivers/isdn/isdnloop/isdnloop.c
> @@ -570,7 +570,7 @@ isdnloop_atimeout(isdnloop_card *card, int ch)
>  	char buf[60];
>  
>  	spin_lock_irqsave(&card->isdnloop_lock, flags);
> -	if (card->rcard) {
> +	if (card->rcard[ch]) {
>  		isdnloop_fake(card->rcard[ch], "DDIS_I", card->rch[ch] + 1);
>  		card->rcard[ch]->rcard[card->rch[ch]] = NULL;
>  		card->rcard[ch] = NULL;
> -- 
> 2.20.0
>
David Miller March 7, 2019, 5:29 p.m. UTC | #2
From: Arnd Bergmann <arnd@arndb.de>
Date: Thu,  7 Mar 2019 10:32:07 +0100

> clang has spotted an ancient code bug and warns about it with:
> 
> drivers/isdn/isdnloop/isdnloop.c:573:12: error: address of array 'card->rcard' will always evaluate to 'true' [-Werror,-Wpointer-bool-conversion]
> 
> This is an array of pointers, so we should check if a specific
> pointer exists in the array before using it, not whether the
> array itself exists.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Applied.
diff mbox series

Patch

diff --git a/drivers/isdn/isdnloop/isdnloop.c b/drivers/isdn/isdnloop/isdnloop.c
index f4253d468ae1..755c6bbc9553 100644
--- a/drivers/isdn/isdnloop/isdnloop.c
+++ b/drivers/isdn/isdnloop/isdnloop.c
@@ -570,7 +570,7 @@  isdnloop_atimeout(isdnloop_card *card, int ch)
 	char buf[60];
 
 	spin_lock_irqsave(&card->isdnloop_lock, flags);
-	if (card->rcard) {
+	if (card->rcard[ch]) {
 		isdnloop_fake(card->rcard[ch], "DDIS_I", card->rch[ch] + 1);
 		card->rcard[ch]->rcard[card->rch[ch]] = NULL;
 		card->rcard[ch] = NULL;