Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1492218
| From | Finn Thain <fthain@telegraphics.com.au> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 3/3] g_NCR5380: Stop using scsi_module.c |
| Date | 2016-09-28 02:10 +0200 |
| Message-ID | <smaBH-7UP-3@gated-at.bofh.it> (permalink) |
| References | <sl17s-56O-7@gated-at.bofh.it> <sl17s-56O-23@gated-at.bofh.it> <sluM9-6Ug-5@gated-at.bofh.it> <sm09k-1bo-23@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Tue, 27 Sep 2016, Ondrej Zary wrote:
> On Monday 26 September 2016, Finn Thain wrote:
>
> [...]
>
> > > @@ -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().
It's funny you say that, I already fixed a few of those use-after-free
bugs in the other 5380 drivers. To avoid the bug, you'd need to use a
temporary variable, like the fixes I did elsewhere.
Don't worry about changing it, this part of the driver gets revisited in
my existing patch queue anyway.
>
> [...]
>
> > > +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;
The problem with that line is that pnp_ret is always discarded, same as in
your version. I think my version makes that clear, which is what matters
to me.
>
> 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.
>
>
FWIW I would hope that the hypothetical definition of this
`module_isa_pnp_driver' macro would have the same properties as my
version: shorter, uses no temporaries and uses one less #ifdef, and is
generally easier for me to read.
--
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/3] g_NCR5380: Modernization Ondrej Zary <linux@rainbow-software.org> - 2016-09-24 21:50 +0200
[PATCH 3/3] g_NCR5380: Stop using scsi_module.c Ondrej Zary <linux@rainbow-software.org> - 2016-09-24 21:50 +0200
Re: [PATCH 3/3] g_NCR5380: Stop using scsi_module.c Christoph Hellwig <hch@infradead.org> - 2016-09-26 02:00 +0200
Re: [PATCH 3/3] g_NCR5380: Stop using scsi_module.c Finn Thain <fthain@telegraphics.com.au> - 2016-09-26 05:30 +0200
Re: [PATCH 3/3] g_NCR5380: Stop using scsi_module.c Ondrej Zary <linux@rainbow-software.org> - 2016-09-27 15:00 +0200
Re: [PATCH 3/3] g_NCR5380: Stop using scsi_module.c Finn Thain <fthain@telegraphics.com.au> - 2016-09-28 02:10 +0200
[PATCH 1/3] g_NCR5380: Remove deprecated __setup Ondrej Zary <linux@rainbow-software.org> - 2016-09-24 21:50 +0200
Re: [PATCH 1/3] g_NCR5380: Remove deprecated __setup Christoph Hellwig <hch@infradead.org> - 2016-09-26 01:50 +0200
Re: [PATCH 1/3] g_NCR5380: Remove deprecated __setup Finn Thain <fthain@telegraphics.com.au> - 2016-09-26 02:50 +0200
[PATCH 4/3] g_NCR5380: Merge g_NCR5380 and g_NCR5380_mmio Ondrej Zary <linux@rainbow-software.org> - 2016-09-25 21:40 +0200
Re: [PATCH 4/3] g_NCR5380: Merge g_NCR5380 and g_NCR5380_mmio Christoph Hellwig <hch@infradead.org> - 2016-09-26 02:00 +0200
Re: [PATCH 4/3] g_NCR5380: Merge g_NCR5380 and g_NCR5380_mmio Finn Thain <fthain@telegraphics.com.au> - 2016-09-26 02:40 +0200
Re: [PATCH 4/3] g_NCR5380: Merge g_NCR5380 and g_NCR5380_mmio Christoph Hellwig <hch@infradead.org> - 2016-09-26 02:50 +0200
Re: [PATCH 4/3] g_NCR5380: Merge g_NCR5380 and g_NCR5380_mmio Finn Thain <fthain@telegraphics.com.au> - 2016-09-28 02:50 +0200
csiph-web