Skip to contentSkip to conversation

bfa: fix bfa_fcb_itnim_alloc() error handling

PATCH RESEND Superseded Dan Carpenter 3 participants 5 messages Apr 13, 2016 – May 10, 2016

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

PATCH RESEND 1/1 bfa: fix bfa_fcb_itnim_alloc() error handling

The caller assumes that "itnim" is NULL on error and non-NULL on success but really "itnim" is uninitialized on error. This function should just use normal error handling where it returns zero on success and negative on failure.

---
Static checker stuff. Not tested.

I sent this originally in 2014 but it still seems to apply fine.

drivers/scsi/bfa/bfa_fcs.h +2 -2
index 42bcb97..af220e9 100644
@@ -873,8 +873,8 @@ bfa_status_t bfa_fcb_rport_alloc(struct bfad_s *bfad,
 /*
  * itnim callbacks
  */
-void bfa_fcb_itnim_alloc(struct bfad_s *bfad, struct bfa_fcs_itnim_s **itnim,
-			 struct bfad_itnim_s **itnim_drv);
+int bfa_fcb_itnim_alloc(struct bfad_s *bfad, struct bfa_fcs_itnim_s **itnim,
+			struct bfad_itnim_s **itnim_drv);
 void bfa_fcb_itnim_free(struct bfad_s *bfad,
 			struct bfad_itnim_s *itnim_drv);
 void bfa_fcb_itnim_online(struct bfad_itnim_s *itnim_drv);
drivers/scsi/bfa/bfad_im.c +3 -2
index 7223b00..31426ae 100644
@@ -413,13 +413,13 @@ bfad_im_slave_destroy(struct scsi_device *sdev)
  * BFA FCS itnim alloc callback, after successful PRLI
  * Context: Interrupt
  */
-void
+int
 bfa_fcb_itnim_alloc(struct bfad_s *bfad, struct bfa_fcs_itnim_s **itnim,
 		    struct bfad_itnim_s **itnim_drv)
 {
 	*itnim_drv = kzalloc(sizeof(struct bfad_itnim_s), GFP_ATOMIC);
 	if (*itnim_drv = NULL)
-		return;
+		return -ENOMEM;
 
 	(*itnim_drv)->im = bfad->im;
 	*itnim = &(*itnim_drv)->fcs_itnim;
@@ -430,6 +430,7 @@ bfa_fcb_itnim_alloc(struct bfad_s *bfad, struct bfa_fcs_itnim_s **itnim,
 	 */
 	INIT_WORK(&(*itnim_drv)->itnim_work, bfad_im_itnim_work_handler);
 	bfad->bfad_flags |= BFAD_RPORT_ONLINE;
+	return 0;
 }
 
 /*
drivers/scsi/bfa/bfa_fcs_fcpim.c +3 -2
index 6dc7926..829247e 100644
@@ -587,12 +587,13 @@ bfa_fcs_itnim_create(struct bfa_fcs_rport_s *rport)
 	struct bfa_fcs_lport_s *port = rport->port;
 	struct bfa_fcs_itnim_s *itnim;
 	struct bfad_itnim_s   *itnim_drv;
+	int ret;
 
 	/*
 	 * call bfad to allocate the itnim
 	 */
-	bfa_fcb_itnim_alloc(port->fcs->bfad, &itnim, &itnim_drv);
-	if (itnim = NULL) {
+	ret = bfa_fcb_itnim_alloc(port->fcs->bfad, &itnim, &itnim_drv);
+	if (ret) {
 		bfa_trc(port->fcs, rport->pwwn);
 		return NULL;
 	}
#1 lore raw

PATCH RESEND v2 1/1 bfa: fix bfa_fcb_itnim_alloc() error handling

The caller assumes that "itnim" is NULL on error and non-NULL on success but really "itnim" is uninitialized on error. This function should just use normal error handling where it returns zero on success and negative on failure.

---
v2: fix up the subject and CC list.

drivers/scsi/bfa/bfa_fcs.h +2 -2
index 42bcb97..af220e9 100644
@@ -873,8 +873,8 @@ bfa_status_t bfa_fcb_rport_alloc(struct bfad_s *bfad,
 /*
  * itnim callbacks
  */
-void bfa_fcb_itnim_alloc(struct bfad_s *bfad, struct bfa_fcs_itnim_s **itnim,
-			 struct bfad_itnim_s **itnim_drv);
+int bfa_fcb_itnim_alloc(struct bfad_s *bfad, struct bfa_fcs_itnim_s **itnim,
+			struct bfad_itnim_s **itnim_drv);
 void bfa_fcb_itnim_free(struct bfad_s *bfad,
 			struct bfad_itnim_s *itnim_drv);
 void bfa_fcb_itnim_online(struct bfad_itnim_s *itnim_drv);
drivers/scsi/bfa/bfad_im.c +3 -2
index 7223b00..31426ae 100644
@@ -413,13 +413,13 @@ bfad_im_slave_destroy(struct scsi_device *sdev)
  * BFA FCS itnim alloc callback, after successful PRLI
  * Context: Interrupt
  */
-void
+int
 bfa_fcb_itnim_alloc(struct bfad_s *bfad, struct bfa_fcs_itnim_s **itnim,
 		    struct bfad_itnim_s **itnim_drv)
 {
 	*itnim_drv = kzalloc(sizeof(struct bfad_itnim_s), GFP_ATOMIC);
 	if (*itnim_drv = NULL)
-		return;
+		return -ENOMEM;
 
 	(*itnim_drv)->im = bfad->im;
 	*itnim = &(*itnim_drv)->fcs_itnim;
@@ -430,6 +430,7 @@ bfa_fcb_itnim_alloc(struct bfad_s *bfad, struct bfa_fcs_itnim_s **itnim,
 	 */
 	INIT_WORK(&(*itnim_drv)->itnim_work, bfad_im_itnim_work_handler);
 	bfad->bfad_flags |= BFAD_RPORT_ONLINE;
+	return 0;
 }
 
 /*
drivers/scsi/bfa/bfa_fcs_fcpim.c +3 -2
index 6dc7926..829247e 100644
@@ -587,12 +587,13 @@ bfa_fcs_itnim_create(struct bfa_fcs_rport_s *rport)
 	struct bfa_fcs_lport_s *port = rport->port;
 	struct bfa_fcs_itnim_s *itnim;
 	struct bfad_itnim_s   *itnim_drv;
+	int ret;
 
 	/*
 	 * call bfad to allocate the itnim
 	 */
-	bfa_fcb_itnim_alloc(port->fcs->bfad, &itnim, &itnim_drv);
-	if (itnim = NULL) {
+	ret = bfa_fcb_itnim_alloc(port->fcs->bfad, &itnim, &itnim_drv);
+	if (ret) {
 		bfa_trc(port->fcs, rport->pwwn);
 		return NULL;
 	}
#2 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Dan" = Dan Carpenter <[email protected]> writes:

Dan> The caller assumes that "itnim" is NULL on error and non-NULL on Dan> success but really "itnim" is uninitialized on error. This Dan> function should just use normal error handling where it returns Dan> zero on success and negative on failure.

Anil, please review:

	https://patchwork.kernel.org/patch/8820751/
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
maintainer
#3 lore raw

Apologies for the delay. Patch looks good.

Acked by: Anil Gurumurthy <[email protected]>

-----Original Message-----
From: Martin K. Petersen [mailto:[email protected]]
Sent: 06 May 2016 06:54
To: Dan Carpenter <[email protected]>
Cc: Anil Gurumurthy <[email protected]>; Sudarsana Kalluru <[email protected]>; James E.J. Bottomley <[email protected]>; Martin K. Petersen <[email protected]>; linux-scsi <[email protected]>; [email protected]
Subject: Re: [PATCH resend v2] [SCSI] bfa: fix bfa_fcb_itnim_alloc() error handling

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Dan" = Dan Carpenter <[email protected]> writes:

Dan> The caller assumes that "itnim" is NULL on error and non-NULL on Dan> success but really "itnim" is uninitialized on error. This Dan> function should just use normal error handling where it returns Dan> zero on success and negative on failure.

Anil, please review:

	https://patchwork.kernel.org/patch/8820751/
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#4 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Anil" = Anil Gurumurthy <[email protected]> writes:

Anil> Apologies for the delay. Patch looks good. Acked by: Anil Anil> Gurumurthy <[email protected]>

Applied to 4.7/scsi-queue.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering