LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] dgnc: move more repeating code under 'failed' label
@ 2015-03-08 17:46 Giedrius Statkevičius
2015-03-09 13:06 ` Dan Carpenter
0 siblings, 1 reply; 3+ messages in thread
From: Giedrius Statkevičius @ 2015-03-08 17:46 UTC (permalink / raw)
To: lidza.louina, markh
Cc: gregkh, driverdev-devel, devel, linux-kernel, Giedrius Statkevičius
Currently the label is only used to return a error code to the caller but more
repeating code is before each "goto failed;" thus we can move that code to the
label. Also, remove some empty unneeded lines together with this patch in those
if's and at the end of dgnc_found_board().
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@gmail.com>
---
drivers/staging/dgnc/dgnc_driver.c | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/drivers/staging/dgnc/dgnc_driver.c b/drivers/staging/dgnc/dgnc_driver.c
index fa1ee79..73ee667 100644
--- a/drivers/staging/dgnc/dgnc_driver.c
+++ b/drivers/staging/dgnc/dgnc_driver.c
@@ -574,17 +574,12 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
if (rc < 0) {
dgnc_tty_uninit(brd);
pr_err(DRVSTR ": Can't register tty devices (%d)\n", rc);
- brd->state = BOARD_FAILED;
- brd->dpastatus = BD_NOFEP;
goto failed;
}
rc = dgnc_finalize_board_init(brd);
if (rc < 0) {
pr_err(DRVSTR ": Can't finalize board init (%d)\n", rc);
- brd->state = BOARD_FAILED;
- brd->dpastatus = BD_NOFEP;
-
goto failed;
}
@@ -592,9 +587,6 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
if (rc < 0) {
dgnc_tty_uninit(brd);
pr_err(DRVSTR ": Can't init tty devices (%d)\n", rc);
- brd->state = BOARD_FAILED;
- brd->dpastatus = BD_NOFEP;
-
goto failed;
}
@@ -628,9 +620,9 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
return 0;
failed:
-
+ brd->state = BOARD_FAILED;
+ brd->dpastatus = BD_NOFEP;
return -ENXIO;
-
}
--
2.3.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] dgnc: move more repeating code under 'failed' label
2015-03-08 17:46 [PATCH] dgnc: move more repeating code under 'failed' label Giedrius Statkevičius
@ 2015-03-09 13:06 ` Dan Carpenter
2015-03-09 15:23 ` Giedrius Statkevičius
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2015-03-09 13:06 UTC (permalink / raw)
To: Giedrius Statkevičius, Matteo Semenzato
Cc: lidza.louina, markh, devel, gregkh, driverdev-devel, linux-kernel
Added Matteo to the CC list because he was working on this function as
well and I remembered something I wanted to tell him.
On Sun, Mar 08, 2015 at 07:46:37PM +0200, Giedrius Statkevičius wrote:
> Currently the label is only used to return a error code to the caller but more
> repeating code is before each "goto failed;" thus we can move that code to the
> label. Also, remove some empty unneeded lines together with this patch in those
> if's and at the end of dgnc_found_board().
>
This function totally sucks.
This patch is useless because we will never use the brd->state in the
cases where we fail. We shouldn't be saving inconsistent crap into
dgnc_Board[] because that is barf inducing ugly even though it's not a
bug given that we don't use it.
Only do:
dgnc_Board[dgnc_NumBoards] = brd;
when the brd is fully configured at the end of the dgnc_found_board()
function.
regards,
dan carpenter
> Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@gmail.com>
> ---
> drivers/staging/dgnc/dgnc_driver.c | 12 ++----------
> 1 file changed, 2 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/staging/dgnc/dgnc_driver.c b/drivers/staging/dgnc/dgnc_driver.c
> index fa1ee79..73ee667 100644
> --- a/drivers/staging/dgnc/dgnc_driver.c
> +++ b/drivers/staging/dgnc/dgnc_driver.c
> @@ -574,17 +574,12 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
> if (rc < 0) {
> dgnc_tty_uninit(brd);
> pr_err(DRVSTR ": Can't register tty devices (%d)\n", rc);
> - brd->state = BOARD_FAILED;
> - brd->dpastatus = BD_NOFEP;
> goto failed;
> }
>
> rc = dgnc_finalize_board_init(brd);
> if (rc < 0) {
> pr_err(DRVSTR ": Can't finalize board init (%d)\n", rc);
> - brd->state = BOARD_FAILED;
> - brd->dpastatus = BD_NOFEP;
> -
> goto failed;
> }
>
> @@ -592,9 +587,6 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
> if (rc < 0) {
> dgnc_tty_uninit(brd);
> pr_err(DRVSTR ": Can't init tty devices (%d)\n", rc);
> - brd->state = BOARD_FAILED;
> - brd->dpastatus = BD_NOFEP;
> -
> goto failed;
> }
>
> @@ -628,9 +620,9 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
> return 0;
>
> failed:
> -
> + brd->state = BOARD_FAILED;
> + brd->dpastatus = BD_NOFEP;
> return -ENXIO;
> -
> }
>
>
> --
> 2.3.2
>
> _______________________________________________
> devel mailing list
> devel@linuxdriverproject.org
> http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] dgnc: move more repeating code under 'failed' label
2015-03-09 13:06 ` Dan Carpenter
@ 2015-03-09 15:23 ` Giedrius Statkevičius
0 siblings, 0 replies; 3+ messages in thread
From: Giedrius Statkevičius @ 2015-03-09 15:23 UTC (permalink / raw)
To: Dan Carpenter, Matteo Semenzato
Cc: lidza.louina, markh, devel, gregkh, driverdev-devel, linux-kernel
On 2015.03.09 15:06, Dan Carpenter wrote:
> Added Matteo to the CC list because he was working on this function as
> well and I remembered something I wanted to tell him.
>
> On Sun, Mar 08, 2015 at 07:46:37PM +0200, Giedrius Statkevičius wrote:
>> Currently the label is only used to return a error code to the caller but more
>> repeating code is before each "goto failed;" thus we can move that code to the
>> label. Also, remove some empty unneeded lines together with this patch in those
>> if's and at the end of dgnc_found_board().
>>
>
> This function totally sucks.
>
> This patch is useless because we will never use the brd->state in the
> cases where we fail. We shouldn't be saving inconsistent crap into
> dgnc_Board[] because that is barf inducing ugly even though it's not a
> bug given that we don't use it.
>
> Only do:
>
> dgnc_Board[dgnc_NumBoards] = brd;
>
> when the brd is fully configured at the end of the dgnc_found_board()
> function.
>
> regards,
> dan carpenter
First time I've made this patch I was purely looking at this from a
cosmetical point. But now that I've looked more at this I see that you
have a good point. I've made a patch that tries to address this issue
and posted it in another thread.
--
Thanks,
Giedrius
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-03-09 15:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-08 17:46 [PATCH] dgnc: move more repeating code under 'failed' label Giedrius Statkevičius
2015-03-09 13:06 ` Dan Carpenter
2015-03-09 15:23 ` Giedrius Statkevičius
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).