Skip to contentSkip to conversation

staging: dgnc: remove redundant NULL check for brd

PATCH Superseded Daeseok Youn 2 participants 5 messages May 20, 2016 – May 27, 2016

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 staging: dgnc: remove redundant NULL check for brd

the "brd" value cannot be NULL in dgnc_finalize_board_init(). Because "brd" as a parameter of this function was already checked for NULL.

---
 drivers/staging/dgnc/dgnc_driver.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/staging/dgnc/dgnc_driver.c +0 -3
index af2e835..22257d2 100644
@@ -579,9 +579,6 @@ static int dgnc_finalize_board_init(struct dgnc_board *brd)
 {
 	int rc = 0;
 
-	if (!brd || brd->magic != DGNC_BOARD_MAGIC)
-		return -ENODEV;
-
 	if (brd->irq) {
 		rc = request_irq(brd->irq, brd->bd_ops->intr,
 				 IRQF_SHARED, "DGNC", brd);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 15 lines · Daeseok Youn

the "brd" value cannot be NULL in dgnc_finalize_board_init(). Because "brd" as a parameter of this function was already checked for NULL.

---
 drivers/staging/dgnc/dgnc_driver.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/staging/dgnc/dgnc_driver.c +0 -0
index af2e835..22257d2 100644

drivers/staging/dgnc/dgnc_driver.c static int dgnc_finalize_board_init(struct dgnc_board *brd) · line 584

Quoted 9 lines
drivers/staging/dgnc/dgnc_driver.c +0 -3
@@ -579,9 +579,6 @@ static int dgnc_finalize_board_init(struct dgnc_board *brd)
 {
 	int rc = 0;
 
-	if (!brd || brd->magic != DGNC_BOARD_MAGIC)
-		return -ENODEV;
-
 	if (brd->irq) {
 		rc = request_irq(brd->irq, brd->bd_ops->intr,
 				 IRQF_SHARED, "DGNC", brd);

This is partially correct, the check for brd being NULL is in line 371.

But there is a second check for brd->magic != DGNC_BOARD_MAGIC. Do you want to keep that one?

Also, how did you find this patch. It is useful to mention this in the commit message if it was through some static analysis tool. For people using these tools in the future.

Thanks for the patch :)
Luis

#2 lore raw

2016-05-26 6:48 GMT+09:00 Luis de Bethencourt <[email protected]>:

Quoted 18 lines · Daeseok Youn
Quoted 17 lines

the "brd" value cannot be NULL in dgnc_finalize_board_init(). Because "brd" as a parameter of this function was already checked for NULL.

---
 drivers/staging/dgnc/dgnc_driver.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/staging/dgnc/dgnc_driver.c +0 -0
index af2e835..22257d2 100644
@@ -579,9 +579,6 @@ static int dgnc_finalize_board_init(struct dgnc_board *brd)
 {
      int rc = 0;
 
Quoted 9 lines

drivers/staging/dgnc/dgnc_driver.c static int dgnc_finalize_board_init(struct dgnc_board *brd) · line 584

Quoted 7 lines
drivers/staging/dgnc/dgnc_driver.c +0 -3
-     if (!brd || brd->magic != DGNC_BOARD_MAGIC)
-             return -ENODEV;
-
      if (brd->irq) {
              rc = request_irq(brd->irq, brd->bd_ops->intr,
                               IRQF_SHARED, "DGNC", brd);

This is partially correct, the check for brd being NULL is in line 371.

Hi Luis,

Yes, right. but also brd was assigned the value DGNC_BOARD_MAGIC in line 384. brd->magic = DGNC_BOARD_MAGIC;
and also dgnc_finalize_board_init() as a static function is only called in dgnc_found_board(), right?

Quoted 3 lines

But there is a second check for brd->magic != DGNC_BOARD_MAGIC. Do you want to keep that one?

So.. I think it doesn't need to check about DGNC_BOARD_MAGIC.

Quoted 4 lines

Also, how did you find this patch. It is useful to mention this in the commit message if it was through some static analysis tool. For people using these tools in the future.

There are some static analysis tool for checking linux kernel code. But I didn't use
those tools for this patch. sometimes, I usually run "smatch" tool for checking linux kernel
code.

thanks.
regards,
Daeseok.

Quoted 3 lines

Thanks for the patch :)
Luis

#3 lore raw
Quoted 36 lines · DaeSeok Youn

2016-05-26 6:48 GMT+09:00 Luis de Bethencourt <[email protected]>:

Quoted 18 lines · Daeseok Youn
Quoted 17 lines

the "brd" value cannot be NULL in dgnc_finalize_board_init(). Because "brd" as a parameter of this function was already checked for NULL.

---
 drivers/staging/dgnc/dgnc_driver.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/staging/dgnc/dgnc_driver.c +0 -0
index af2e835..22257d2 100644
@@ -579,9 +579,6 @@ static int dgnc_finalize_board_init(struct dgnc_board *brd)
 {
      int rc = 0;
 
Quoted 9 lines

drivers/staging/dgnc/dgnc_driver.c static int dgnc_finalize_board_init(struct dgnc_board *brd) · line 584

Quoted 7 lines
drivers/staging/dgnc/dgnc_driver.c +0 -3
-     if (!brd || brd->magic != DGNC_BOARD_MAGIC)
-             return -ENODEV;
-
      if (brd->irq) {
              rc = request_irq(brd->irq, brd->bd_ops->intr,
                               IRQF_SHARED, "DGNC", brd);

This is partially correct, the check for brd being NULL is in line 371.

Hi Luis,

Yes, right. but also brd was assigned the value DGNC_BOARD_MAGIC in line 384. brd->magic = DGNC_BOARD_MAGIC;
and also dgnc_finalize_board_init() as a static function is only called in dgnc_found_board(), right?

Quoted 1 line
Quoted 3 lines
Quoted 2 lines

But there is a second check for brd->magic != DGNC_BOARD_MAGIC. Do you want to keep that one?

So.. I think it doesn't need to check about DGNC_BOARD_MAGIC.

This is good. I was asking just to make sure it was your intention.

Please add the reason to drop that second check in the commit message as well. So people reading the git log can understand both parts. For both patches.

Thanks for the fixes :)

Luis

Quoted 18 lines
Quoted 5 lines

Also, how did you find this patch. It is useful to mention this in the commit message if it was through some static analysis tool. For people using these tools in the future.

There are some static analysis tool for checking linux kernel code. But I didn't use
those tools for this patch. sometimes, I usually run "smatch" tool for checking linux kernel
code.

thanks.
regards,
Daeseok.

Quoted 3 lines

Thanks for the patch :)
Luis

#4 lore raw

2016-05-26 21:29 GMT+09:00 Luis de Bethencourt <[email protected]>:

Quoted 37 lines · DaeSeok Youn
Quoted 36 lines

2016-05-26 6:48 GMT+09:00 Luis de Bethencourt <[email protected]>:

Quoted 18 lines · Daeseok Youn
Quoted 17 lines

the "brd" value cannot be NULL in dgnc_finalize_board_init(). Because "brd" as a parameter of this function was already checked for NULL.

---
 drivers/staging/dgnc/dgnc_driver.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/staging/dgnc/dgnc_driver.c +0 -0
index af2e835..22257d2 100644
@@ -579,9 +579,6 @@ static int dgnc_finalize_board_init(struct dgnc_board *brd)
 {
      int rc = 0;
 
Quoted 9 lines

drivers/staging/dgnc/dgnc_driver.c static int dgnc_finalize_board_init(struct dgnc_board *brd) · line 584

Quoted 7 lines
drivers/staging/dgnc/dgnc_driver.c +0 -3
-     if (!brd || brd->magic != DGNC_BOARD_MAGIC)
-             return -ENODEV;
-
      if (brd->irq) {
              rc = request_irq(brd->irq, brd->bd_ops->intr,
                               IRQF_SHARED, "DGNC", brd);

This is partially correct, the check for brd being NULL is in line 371.

Hi Luis,

Yes, right. but also brd was assigned the value DGNC_BOARD_MAGIC in line 384. brd->magic = DGNC_BOARD_MAGIC;
and also dgnc_finalize_board_init() as a static function is only called in dgnc_found_board(), right?

Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

But there is a second check for brd->magic != DGNC_BOARD_MAGIC. Do you want to keep that one?

So.. I think it doesn't need to check about DGNC_BOARD_MAGIC.

This is good. I was asking just to make sure it was your intention.

Please add the reason to drop that second check in the commit message as well. So people reading the git log can understand both parts. For both patches.

OK. I will update the change log and resend it.

Thanks.

regards,
Daeseok.

Quoted 24 lines

Thanks for the fixes :)

Luis

Quoted 18 lines
Quoted 5 lines

Also, how did you find this patch. It is useful to mention this in the commit message if it was through some static analysis tool. For people using these tools in the future.

There are some static analysis tool for checking linux kernel code. But I didn't use
those tools for this patch. sometimes, I usually run "smatch" tool for checking linux kernel
code.

thanks.
regards,
Daeseok.

Quoted 3 lines

Thanks for the patch :)
Luis