From: David Brownell <david-b@pacbell.net>
To: Jean Delvare <khali@linux-fr.org>
Cc: linuxppc-dev@ozlabs.org, Linux I2C <i2c@lm-sensors.org>
Subject: Re: [PATCH 2/3] i2c: Convert all new-style drivers to use module aliasing
Date: Sun, 27 Jan 2008 10:40:19 -0800 [thread overview]
Message-ID: <200801271040.20248.david-b@pacbell.net> (raw)
In-Reply-To: <20080121114139.3aaa111a@hyperion.delvare>
General comment: if you're going to index arrays by enum
values, it's best to initialize them that way too. Else
you're expecting a particular optional policy for how the
enums get grown...
- Dave
On Monday 21 January 2008, Jean Delvare wrote:
> --- linux-2.6.24-rc8.orig/drivers/rtc/rtc-ds1307.c 2008-01-20 17:26:58.000000000 +0100
> +++ linux-2.6.24-rc8/drivers/rtc/rtc-ds1307.c 2008-01-20 19:03:48.000000000 +0100
> @@ -102,42 +102,36 @@ struct chip_desc {
> char name[9];
> unsigned nvram56:1;
> unsigned alarm:1;
> - enum ds_type type;
> };
>
> static const struct chip_desc chips[] = { {
> .name = "ds1307",
> - .type = ds_1307,
> .nvram56 = 1,
> }, {
So tables like this would become
[ds1307] = { ... },
[ds1337] = { ... },
> .name = "ds1337",
> - .type = ds_1337,
> .alarm = 1,
> }, {
> .name = "ds1338",
> - .type = ds_1338,
> .nvram56 = 1,
> }, {
> .name = "ds1339",
> - .type = ds_1339,
> .alarm = 1,
> }, {
> .name = "ds1340",
> - .type = ds_1340,
> }, {
> .name = "m41t00",
> - .type = m41t00,
> }, };
>
> -static inline const struct chip_desc *find_chip(const char *s)
> -{
> - unsigned i;
> -
> - for (i = 0; i < ARRAY_SIZE(chips); i++)
> - if (strnicmp(s, chips[i].name, sizeof chips[i].name) == 0)
> - return &chips[i];
> - return NULL;
> -}
> +static const struct i2c_device_id ds1307_id[] = {
> + { "ds1307", ds_1307 },
> + { "ds1337", ds_1337 },
> + { "ds1338", ds_1338 },
> + { "ds1339", ds_1339 },
> + { "ds1340", ds_1340 },
> + { "m41t00", m41t00 },
> + {},
> +};
> +MODULE_DEVICE_TABLE(i2c, ds1307_id);
>
> static int ds1307_get_time(struct device *dev, struct rtc_time *t)
> {
> @@ -335,12 +329,7 @@ static int __devinit ds1307_probe(struct
> const struct chip_desc *chip;
> struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
>
> - chip = find_chip(client->name);
> - if (!chip) {
> - dev_err(&client->dev, "unknown chip type '%s'\n",
> - client->name);
> - return -ENODEV;
> - }
> + chip = &chips[id->driver_data];
... and that would *ensure* such lines always work right,
no matter how the enum values grow.
>
> if (!i2c_check_functionality(adapter,
> I2C_FUNC_I2C | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
next prev parent reply other threads:[~2008-01-27 18:40 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-21 10:25 [PATCH 0/3] i2c: Use the standard, alias-based device/driver matching scheme Jean Delvare
2008-01-21 10:39 ` [PATCH 1/3] i2c: Add support for device alias names Jean Delvare
2008-01-21 10:41 ` [PATCH 2/3] i2c: Convert all new-style drivers to use module aliasing Jean Delvare
[not found] ` <20080121114139.3aaa111a-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-01-21 16:50 ` Jon Smirl
2008-01-21 16:50 ` Jon Smirl
2008-01-22 10:09 ` Jean Delvare
2008-01-27 18:40 ` David Brownell [this message]
2008-01-27 19:21 ` Jon Smirl
2008-04-27 16:56 ` Jean Delvare
[not found] ` <20080121112517.6fe35a89-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-01-21 10:43 ` [PATCH 3/3] i2c: Kill the old driver matching scheme Jean Delvare
2008-01-21 10:43 ` Jean Delvare
2008-01-21 10:49 ` [PATCH 0/3] i2c: Use the standard, alias-based device/driver " Rudolf Marek
2008-01-21 10:49 ` [i2c] " Rudolf Marek
2008-01-21 12:34 ` Jean Delvare
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=200801271040.20248.david-b@pacbell.net \
--to=david-b@pacbell.net \
--cc=i2c@lm-sensors.org \
--cc=khali@linux-fr.org \
--cc=linuxppc-dev@ozlabs.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.