Skip to contentSkip to conversation

staging: dgap: make dgap_found_board() return a brd pointer

PATCH Superseded Daeseok Youn 2 participants 3 messages Jun 20, 2014 Staging

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: dgap: make dgap_found_board() return a brd pointer

Make dgap_found_board() return a brd pointer and that brd pointer assign to dgap_board[] in the end of the dgap_init_one().

---
 drivers/staging/dgap/dgap.c |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)
drivers/staging/dgap/dgap.c +11 -11
index 5c8e622..55c9761 100644
@@ -70,7 +70,8 @@ MODULE_SUPPORTED_DEVICE("dgap");
 
 static int dgap_start(void);
 static void dgap_init_globals(void);
-static int dgap_found_board(struct pci_dev *pdev, int id, int boardnum);
+static struct board_t *dgap_found_board(struct pci_dev *pdev, int id,
+					int boardnum);
 static void dgap_cleanup_board(struct board_t *brd);
 static void dgap_poll_handler(ulong dummy);
 static int dgap_init_pci(void);
@@ -582,11 +583,10 @@ static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (rc)
 		return -EIO;
 
-	rc = dgap_found_board(pdev, ent->driver_data, dgap_numboards);
-	if (rc)
+	brd = dgap_found_board(pdev, ent->driver_data, dgap_numboards);
+	if (IS_ERR(brd))
 		return rc;
 
-	brd = dgap_board[dgap_numboards++];
 	rc = dgap_firmware_load(pdev, ent->driver_data, brd);
 	if (rc)
 		goto cleanup_brd;
@@ -617,6 +617,8 @@ static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	brd->state = BOARD_READY;
 	brd->dpastatus = BD_RUNNING;
 
+	dgap_board[dgap_numboards++] = brd;
+
 	return 0;
 
 tty_free:
@@ -717,7 +719,8 @@ static void dgap_cleanup_board(struct board_t *brd)
  *
  * A board has been found, init it.
  */
-static int dgap_found_board(struct pci_dev *pdev, int id, int boardnum)
+static struct board_t *dgap_found_board(struct pci_dev *pdev, int id,
+					int boardnum)
 {
 	struct board_t *brd;
 	unsigned int pci_irq;
@@ -727,9 +730,7 @@ static int dgap_found_board(struct pci_dev *pdev, int id, int boardnum)
 	/* get the board structure and prep it */
 	brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
 	if (!brd)
-		return -ENOMEM;
-
-	dgap_board[boardnum] = brd;
+		return ERR_PTR(-ENOMEM);
 
 	/* store the info for the board we've found */
 	brd->magic = DGAP_BOARD_MAGIC;
@@ -828,13 +829,12 @@ static int dgap_found_board(struct pci_dev *pdev, int id, int boardnum)
 	pr_info("dgap: board %d: %s (rev %d), irq %ld\n",
 		boardnum, brd->name, brd->rev, brd->irq);
 
-	return 0;
+	return brd;
 
 free_brd:
 	kfree(brd);
-	dgap_board[boardnum] = NULL;
 
-	return ret;
+	return ERR_PTR(ret);
 }
 
 
Signature · 1 line
1.7.1
#1 lore raw

drivers/staging/dgap/dgap.c static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 588

Quoted 5 lines · Daeseok Youn
drivers/staging/dgap/dgap.c +2 -2
-	rc = dgap_found_board(pdev, ent->driver_data, dgap_numboards);
-	if (rc)
+	brd = dgap_found_board(pdev, ent->driver_data, dgap_numboards);
+	if (IS_ERR(brd))
 		return rc;
		return ERR_PTR(brd);

drivers/staging/dgap/dgap.c static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 620

Quoted 10 lines
drivers/staging/dgap/dgap.c +1 -1
-	brd = dgap_board[dgap_numboards++];
 	rc = dgap_firmware_load(pdev, ent->driver_data, brd);
 	if (rc)
 		goto cleanup_brd;
@@ -617,6 +617,8 @@ static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	brd->state = BOARD_READY;
 	brd->dpastatus = BD_RUNNING;
 
+	dgap_board[dgap_numboards++] = brd;

You need to update the error handling of this function to remove the reference do dgap_board[] as well.

drivers/staging/dgap/dgap.c static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 623

Quoted 3 lines
drivers/staging/dgap/dgap.c +1 -0
+
 	return 0;
 

regards,
dan carpenter

#2 lore raw

Hi, Dan.

2014-06-20 18:09 GMT+09:00 Dan Carpenter <[email protected]>:

Quoted 8 lines · Daeseok Youn

drivers/staging/dgap/dgap.c static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 588

Quoted 5 lines
drivers/staging/dgap/dgap.c +2 -2
-     rc = dgap_found_board(pdev, ent->driver_data, dgap_numboards);
-     if (rc)
+     brd = dgap_found_board(pdev, ent->driver_data, dgap_numboards);
+     if (IS_ERR(brd))
              return rc;
                return ERR_PTR(brd);

ok.. you mean PTR_ERR(brd), right?
I will send it again after changing from rc to "PTR_ERR(brd)"

Quoted 11 lines
Quoted 11 lines
drivers/staging/dgap/dgap.c +0 -1
-     brd = dgap_board[dgap_numboards++];
      rc = dgap_firmware_load(pdev, ent->driver_data, brd);
      if (rc)
              goto cleanup_brd;
@@ -617,6 +617,8 @@ static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
      brd->state = BOARD_READY;
      brd->dpastatus = BD_RUNNING;
 
Quoted 4 lines

drivers/staging/dgap/dgap.c static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 620

Quoted 1 line
drivers/staging/dgap/dgap.c +1 -0
+     dgap_board[dgap_numboards++] = brd;

You need to update the error handling of this function to remove the reference do dgap_board[] as well.

Yes, It need to update code in cleanup_brd label.

Thanks
regards,
Daeseok Youn

Quoted 8 lines

drivers/staging/dgap/dgap.c static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 623

Quoted 4 lines
drivers/staging/dgap/dgap.c +1 -0
+
      return 0;
 

regards,
dan carpenter