linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ondrej Zary <linux@rainbow-software.org>
To: Finn Thain <fthain@telegraphics.com.au>
Cc: Christoph Hellwig <hch@infradead.org>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] g_NCR5380: Stop using scsi_module.c
Date: Tue, 27 Sep 2016 14:55:17 +0200	[thread overview]
Message-ID: <201609271455.17930.linux@rainbow-software.org> (raw)
In-Reply-To: <alpine.LNX.2.00.1609261132001.4881@nippy.intranet>

On Monday 26 September 2016, Finn Thain wrote:

[...]

> Instead of this:
> > +	if (scsi_add_host(instance, pdev)) {
> > +		free_irq(irq, instance);
> > +		goto out_unregister;
> > +	}
> > +	scsi_scan_host(instance);
> > +	return instance;
>
> please use the following (note the missing NCR5380_exit() call):
>
> +	if (scsi_add_host(instance, pdev))
> +		goto out_free_irq;
> +	scsi_scan_host(instance);
> +	return(instance);
> +
> +out_free_irq:
> +	if (instance->irq != NO_IRQ)
> +		free_irq(instance->irq, instance);
> +	NCR5380_exit(instance);
>
> >  out_unregister:
> > -	scsi_unregister(instance);
> > +	scsi_host_put(instance);
> >  out_release:
> >  #ifndef SCSI_G_NCR5380_MEM
> > -	release_region(card.NCR5380_map_name, region_size);
> > +	release_region(base, region_size);
> >  #else
> >  	iounmap(iomem);
> >  	release_mem_region(base, iomem_size);
> >  #endif
> > -	return 0;
> > +	return NULL;
> >  }
> >
> > -/**
> > - *	generic_NCR5380_release_resources	-	free resources
> > - *	@instance: host adapter to clean up
> > - *
> > - *	Free the generic interface resources from this adapter.
> > - *
> > - *	Locks: none
> > - */
> > -
> > -static int generic_NCR5380_release_resources(struct Scsi_Host *instance)
> > +static void generic_NCR5380_release_resources(struct Scsi_Host
> > *instance) {
> > +	scsi_remove_host(instance);
> >  	if (instance->irq != NO_IRQ)
> >  		free_irq(instance->irq, instance);
> >  	NCR5380_exit(instance);
> > @@ -364,7 +304,7 @@ static int generic_NCR5380_release_resources(struct
> > Scsi_Host *instance) release_mem_region(instance->base,
> > hostdata->iomem_size);
> >  	}
> >  #endif
> > -	return 0;
> > +	scsi_host_put(instance);
>
> The sequence of operations here should be the same as the error path
> above.

I put scsi_host_put() call at the end because the release_mem_region code (in 
the MMIO case) dereferences the hostdata pointer. I don't think it's safe to 
do after scsi_host_put().

[...]

> > +static int pnp_registered;
> > +#endif /* !defined(SCSI_G_NCR5380_MEM) && defined(CONFIG_PNP) */
> > +
> > +static int __init generic_NCR5380_init(void)
> > +{
> > +	int ret = 0;
> > +
> > +#if !defined(SCSI_G_NCR5380_MEM) && defined(CONFIG_PNP)
> > +	ret = pnp_register_driver(&generic_NCR5380_pnp_driver);
> > +	if (!ret)
> > +		pnp_registered = 1;
> >  #endif
> > +	ret = isa_register_driver(&generic_NCR5380_isa_driver, MAX_CARDS);
> > +	if (!ret)
> > +		isa_registered = 1;
> > +
> > +#if !defined(SCSI_G_NCR5380_MEM) && defined(CONFIG_PNP)
> > +	if (pnp_registered)
> > +		ret = 0;
> > +#endif
> > +	if (isa_registered)
> > +		ret = 0;
> > +
> > +	return ret;
> > +}
> > +
> > +static void __exit generic_NCR5380_exit(void)
> > +{
> > +#if !defined(SCSI_G_NCR5380_MEM) && defined(CONFIG_PNP)
> > +	if (pnp_registered)
> > +		pnp_unregister_driver(&generic_NCR5380_pnp_driver);
> > +#endif
> > +	if (isa_registered)
> > +		isa_unregister_driver(&generic_NCR5380_isa_driver);
> > +}
> > +
>
> I find that hard to follow. This should be equivalent and simpler:
>
> static int __init generic_NCR5380_init(void)
> {
> 	isa_ret = isa_register_driver(&generic_NCR5380_isa_driver, MAX_CARDS);
> #if !defined(SCSI_G_NCR5380_MEM) && defined(CONFIG_PNP)
> 	pnp_ret = pnp_register_driver(&generic_NCR5380_pnp_driver);
> 	return pnp_ret ? isa_ret : 0;
> #endif
> 	return isa_ret;
> }
>
> static void __exit generic_NCR5380_exit(void)
> {
> 	if (!isa_ret)
> 		isa_unregister_driver(&generic_NCR5380_isa_driver);
> #if !defined(SCSI_G_NCR5380_MEM) && defined(CONFIG_PNP)
> 	if (!pnp_ret)
> 		pnp_unregister_driver(&generic_NCR5380_pnp_driver);
> #endif
> }

Doesn't make it any better, IMHO. Good that it's shorter but not cleaner - 
especially this:
> 	return pnp_ret ? isa_ret : 0;

Also looking at the _exit function, meaning of isa_ret and pnp_ret is not 
obvious there.

Maybe we should have a module_isa_pnp_driver() macro.

-- 
Ondrej Zary

  reply	other threads:[~2016-09-27 12:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-24 18:59 [PATCH 0/3] g_NCR5380: Modernization Ondrej Zary
2016-09-24 18:59 ` [PATCH 1/3] g_NCR5380: Remove deprecated __setup Ondrej Zary
2016-09-25 23:45   ` Christoph Hellwig
2016-09-26  0:46   ` Finn Thain
2016-09-24 18:59 ` [PATCH 2/3] g_NCR5380: Reduce overrides[] from array to struct Ondrej Zary
2016-09-25 23:46   ` Christoph Hellwig
2016-09-26  3:56   ` Finn Thain
2016-09-24 18:59 ` [PATCH 3/3] g_NCR5380: Stop using scsi_module.c Ondrej Zary
2016-09-25 23:50   ` Christoph Hellwig
2016-09-26  3:29   ` Finn Thain
2016-09-27 12:55     ` Ondrej Zary [this message]
2016-09-28  0:06       ` Finn Thain
2016-09-25 19:39 ` [PATCH 4/3] g_NCR5380: Merge g_NCR5380 and g_NCR5380_mmio Ondrej Zary
2016-09-25 23:55   ` Christoph Hellwig
2016-09-26  0:37     ` Finn Thain
2016-09-26  0:49       ` Christoph Hellwig
2016-09-28  0:49   ` Finn Thain
  -- strict thread matches above, loose matches on Subject: below --
2016-09-27 19:00 [PATCH v2 0/3] g_NCR5380: Modernization Ondrej Zary
2016-09-27 19:00 ` [PATCH 3/3] g_NCR5380: Stop using scsi_module.c Ondrej Zary
2016-09-28 22:57   ` Finn Thain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201609271455.17930.linux@rainbow-software.org \
    --to=linux@rainbow-software.org \
    --cc=fthain@telegraphics.com.au \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).