kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: dgnc: Remove useless and deadly judgment
@ 2016-02-29  6:41 Navy Cheng
  2016-02-29  7:58 ` Valdis.Kletnieks at vt.edu
  2016-03-11 21:29 ` Greg Kroah-Hartman
  0 siblings, 2 replies; 4+ messages in thread
From: Navy Cheng @ 2016-02-29  6:41 UTC (permalink / raw)
  To: kernelnewbies

pci_unregister_driver() should be used once dgnc module exit. It has
nothing to do with dgnc_NumBoards. Remove the judgment of dgnc_NumBoards to
avoid pci_unregister_driver() is not used when dgnc_NumBoards is 0.

Signed-off-by: Navy Cheng <navych@126.com>
---
 drivers/staging/dgnc/dgnc_driver.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_driver.c b/drivers/staging/dgnc/dgnc_driver.c
index fc6d298..20b0c3b 100644
--- a/drivers/staging/dgnc/dgnc_driver.c
+++ b/drivers/staging/dgnc/dgnc_driver.c
@@ -156,8 +156,7 @@ static void dgnc_cleanup_module(void)
 
 	dgnc_tty_post_uninit();
 
-	if (dgnc_NumBoards)
-		pci_unregister_driver(&dgnc_driver);
+	pci_unregister_driver(&dgnc_driver);
 }
 
 /*
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] staging: dgnc: Remove useless and deadly judgment
  2016-02-29  6:41 [PATCH] staging: dgnc: Remove useless and deadly judgment Navy Cheng
@ 2016-02-29  7:58 ` Valdis.Kletnieks at vt.edu
  2016-02-29 12:27   ` Navy Cheng
  2016-03-11 21:29 ` Greg Kroah-Hartman
  1 sibling, 1 reply; 4+ messages in thread
From: Valdis.Kletnieks at vt.edu @ 2016-02-29  7:58 UTC (permalink / raw)
  To: kernelnewbies

On Mon, 29 Feb 2016 14:41:34 +0800, Navy Cheng said:
> pci_unregister_driver() should be used once dgnc module exit. It has
> nothing to do with dgnc_NumBoards. Remove the judgment of dgnc_NumBoards to
> avoid pci_unregister_driver() is not used when dgnc_NumBoards is 0.

> -	if (dgnc_NumBoards)
> -		pci_unregister_driver(&dgnc_driver);
> +	pci_unregister_driver(&dgnc_driver);

Does pci_unregister_driver do the right thing if there are 0 boards
in the system?

If this logic is wrong, shouldn't there also be a patch fixing the
following in dgnc_init_module()?

        /*
         * Find and configure all the cards
         */
        rc = pci_register_driver(&dgnc_driver);

        /*
         * If something went wrong in the scan, bail out of driver.
         */
        if (rc < 0) {
                /* Only unregister if it was actually registered. */
                if (dgnc_NumBoards)
                        pci_unregister_driver(&dgnc_driver);
                else
                        pr_warn("WARNING: dgnc driver load failed.  No Digi Neo or Classic boards found.\n");

                dgnc_cleanup_module();

While I'm@it, the entire NumBoards counting seems to be wonky - it looks
like a *lot* of off-by-one errors.  Looks like the programmer(s) weren't sure
if they wanted to use that as a zero-based or one-based counter/index.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 848 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160229/4896e710/attachment.bin 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] staging: dgnc: Remove useless and deadly judgment
  2016-02-29  7:58 ` Valdis.Kletnieks at vt.edu
@ 2016-02-29 12:27   ` Navy Cheng
  0 siblings, 0 replies; 4+ messages in thread
From: Navy Cheng @ 2016-02-29 12:27 UTC (permalink / raw)
  To: kernelnewbies

On Mon, Feb 29, 2016 at 02:58:16AM -0500, Valdis.Kletnieks at vt.edu wrote:
> On Mon, 29 Feb 2016 14:41:34 +0800, Navy Cheng said:
> > pci_unregister_driver() should be used once dgnc module exit. It has
> > nothing to do with dgnc_NumBoards. Remove the judgment of dgnc_NumBoards to
> > avoid pci_unregister_driver() is not used when dgnc_NumBoards is 0.
> 
> > -	if (dgnc_NumBoards)
> > -		pci_unregister_driver(&dgnc_driver);
> > +	pci_unregister_driver(&dgnc_driver);
> 
> Does pci_unregister_driver do the right thing if there are 0 boards
> in the system?

I have no dgnc device in my laptop. After *insmod* and *rmmod* dgnc module,
I can re-insmod dgnc successfully. If dgnc is *rmmod*, the dgnc-file in /sys
will disappear.

> If this logic is wrong, shouldn't there also be a patch fixing the
> following in dgnc_init_module()?

Yes, I thought dgnc_init_module should be fixed. But I'm not familiar with
how to submitting patchset. I decide to fix dgnc_cleanup_module() first.

>         /*
>          * Find and configure all the cards
>          */
>         rc = pci_register_driver(&dgnc_driver);
> 
>         /*
>          * If something went wrong in the scan, bail out of driver.
>          */
>         if (rc < 0) {
>                 /* Only unregister if it was actually registered. */
>                 if (dgnc_NumBoards)
>                         pci_unregister_driver(&dgnc_driver);
>                 else
>                         pr_warn("WARNING: dgnc driver load failed.  No Digi Neo or Classic boards found.\n");
> 
>                 dgnc_cleanup_module();
> 
> While I'm at it, the entire NumBoards counting seems to be wonky - it looks
> like a *lot* of off-by-one errors.  Looks like the programmer(s) weren't sure
> if they wanted to use that as a zero-based or one-based counter/index.
> 

Maybe we can fix the *init* and *exit* like this:

    static int __init dgnc_init_module(void)
    {
        int rc;

        rc = dgnc_start();
	if (rc < 0)
            goto err1;

        rc = pci_register_driver(&dgnc_driver)
	if (rc <0) {
	    goto err1;
	    pr_warn("....");
	}

        rc = dgnc_create_driver_sysfiles(&dgnc_driver);

	if (rc = 0)
            goto err2;

	return rc;
	 
    err2:
        pci_unregister_driver(&dgnc_driver);
    err1:
        dgnc_end();

	return rc;
    }
    
    static void dgnc_cleanup_module(void)
    {
        int i;

	dgnc_remove_driver_sysfiles(&dgnc_driver);

	for (i = 0; i < dgnc_NumBoards; ++i) {
	    dgnc_remove_ports_sysfiles(dgnc_Board[i]);
            dgnc_tty_uninit(dgnc_Board[i]);
	    dgnc_cleanup_board(dgnc_Board[i]);
	}

        pci_unregister_driver(&dgnc_driver);

     	dgnc_end();
    }
	

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] staging: dgnc: Remove useless and deadly judgment
  2016-02-29  6:41 [PATCH] staging: dgnc: Remove useless and deadly judgment Navy Cheng
  2016-02-29  7:58 ` Valdis.Kletnieks at vt.edu
@ 2016-03-11 21:29 ` Greg Kroah-Hartman
  1 sibling, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2016-03-11 21:29 UTC (permalink / raw)
  To: kernelnewbies

On Mon, Feb 29, 2016 at 02:41:34PM +0800, Navy Cheng wrote:
> pci_unregister_driver() should be used once dgnc module exit. It has
> nothing to do with dgnc_NumBoards. Remove the judgment of dgnc_NumBoards to
> avoid pci_unregister_driver() is not used when dgnc_NumBoards is 0.
> 
> Signed-off-by: Navy Cheng <navych@126.com>
> ---
>  drivers/staging/dgnc/dgnc_driver.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/dgnc/dgnc_driver.c b/drivers/staging/dgnc/dgnc_driver.c
> index fc6d298..20b0c3b 100644
> --- a/drivers/staging/dgnc/dgnc_driver.c
> +++ b/drivers/staging/dgnc/dgnc_driver.c
> @@ -156,8 +156,7 @@ static void dgnc_cleanup_module(void)
>  
>  	dgnc_tty_post_uninit();
>  
> -	if (dgnc_NumBoards)
> -		pci_unregister_driver(&dgnc_driver);
> +	pci_unregister_driver(&dgnc_driver);
>  }
>  
>  /*

Someone else sent a patch that did much this same thing 2 days before
you did.

Also please use the get_maintainers.pl file to determine the correct
mailing list to send patches like this to (hint, it's not
kernelnewbies...)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-03-11 21:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-29  6:41 [PATCH] staging: dgnc: Remove useless and deadly judgment Navy Cheng
2016-02-29  7:58 ` Valdis.Kletnieks at vt.edu
2016-02-29 12:27   ` Navy Cheng
2016-03-11 21:29 ` Greg Kroah-Hartman

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).