From: u.kleine-koenig@pengutronix.de (Uwe Kleine-König)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCHv2] mc13xxx: Add i2c support for mc13xxx-core
Date: Thu, 16 Dec 2010 10:02:10 +0100 [thread overview]
Message-ID: <20101216090210.GE1940@pengutronix.de> (raw)
In-Reply-To: <201012161930.17299.marc@cpdesign.com.au>
Hello Marc,
> > pdev is a usual name for 'struct platform_device's, so can you please
> > use 'dev'?
>
> no worries.
> (My old habit of putting a 'p' in front of every pointer name. But let's leave
> that there.. :)
You're not working for Microsoft, are you?
> > > + enum mc13xxx_id ictype;
> > > +
> > >
> > > struct mutex lock;
> > > int irq;
> >
> > Before your patch this member was unused. And AFAICT you don't really
> > need it. (Whenever you need the number contained in it, you are in an
> > spi or i2c specific function so you can use spidev->irq or
> > i2cclient->irq.) So can you please just drop this member?
>
> no worries. (Last round of comments you suggested to do in a different patch).
Both is fine IMHO. If you do it in one patch you should just note it in
the commit log.
> > > + int (*read_dev)(struct mc13xxx*, unsigned int, u32*);
> > > + int (*write_dev)(struct mc13xxx*, unsigned int, u32);
> >
> > space between type and asterisk?
>
> Not sure which asterisk you're talking about. (Checkpatch.pl resulted in no
> errors/warnings, so I'm ignorant past that)
I want
int (*read_dev)(struct mc13xxx *, unsigned int, u32 *);
> > > static int __init mc13xxx_init(void)
> > > {
> > >
> > > - return spi_register_driver(&mc13xxx_driver);
> > > + int i2cret;
> > > + int spiret;
> > > + i2cret = i2c_add_driver(&mc13xxx_i2c_driver);
> > > + spiret = spi_register_driver(&mc13xxx_driver);
> > > +
> > > + return (i2cret == 0) && (spiret == 0);
> >
> > If i2c_add_driver succeeds but spi_register_driver you return
> > -ESOMETHING, and the module is discarded while the i2c core keeps a
> > reference to &mc13xxx_i2c_driver. This is bad.
> > I think you need to do:
> >
> > ret = i2c_add_driver(..)
> > if (ret)
> > return ret;
> >
> > ret = spi_register_driver(...)
> > if (ret)
> > i2c_del_driver(...)
> >
> > return ret;
> >
>
> This was my biggest reservation with this code too. I think it should try to
> register both, but should clean appropriately if one fails. (What to return
> from mc13xxx_init() in that case? Or maybe should it be split into separate
> files?).
Don't split, in general your approach is fine. And there are two
possibilities to handle spi vs. i2c:
a) (as suggested above) do both, if at least one fails, do none
This is easier and probably OK.
b) You could still succeed if at least one registration doesn't fail.
Then you need to remember which was successful and only clean this
one up in the remove callback. You could then even depend on I2C
|| SPI.
(BTW, did you fix the dependencies? Currently you need to depend
on I2C && SPI. (Not sure these are the correct names, you may want
to double check that.))
This is more flexible but IMHO not worth the effort.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-K?nig |
Industrial Linux Solutions | http://www.pengutronix.de/ |
next prev parent reply other threads:[~2010-12-16 9:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-15 21:47 [PATCHv2] mc13xxx: Add i2c support for mc13xxx-core Marc Reilly
2010-12-16 7:47 ` Uwe Kleine-König
2010-12-16 8:30 ` Marc Reilly
2010-12-16 9:02 ` Uwe Kleine-König [this message]
2010-12-16 9:20 ` Wolfram Sang
2010-12-17 6:44 ` Marc Reilly
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=20101216090210.GE1940@pengutronix.de \
--to=u.kleine-koenig@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.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).