public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
From: Felipe Balbi <me@felipebalbi.com>
To: Anton Vorontsov <avorontsov@ru.mvista.com>
Cc: Felipe Balbi <felipe.balbi@nokia.com>,
	linux-omap@vger.kernel.org, Anton Vorontsov <cbou@mail.ru>,
	David Woodhouse <dwmw2@infradead.org>
Subject: Re: [PATCH 2/4] power_supply: bq27200: separate bq27200-specific driver
Date: Sun, 19 Oct 2008 01:34:54 +0300	[thread overview]
Message-ID: <20081018223442.GV31842@frodo> (raw)
In-Reply-To: <20081018214635.GA12264@oksana.dev.rtsoft.ru>

On Sun, Oct 19, 2008 at 01:46:35AM +0400, Anton Vorontsov wrote:
> > diff --git a/drivers/power/bq27200.c b/drivers/power/bq27200.c
> > new file mode 100644
> > index 0000000..ef03743
> > --- /dev/null
> > +++ b/drivers/power/bq27200.c
> > @@ -0,0 +1,202 @@
> > +/*
> > + * bq27200.c - BQ27200 battery driver
> > + *
> > + * Copyright (C) 2008 Texas Instruments, Inc.
> > + * Copyright (C) 2008 Nokia Corporation
> > + *
> > + * Author: Texas Instruments
> > + *
> > + * This package is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 as
> > + * published by the Free Software Foundation.
> > + *
> > + * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
> > + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
> > + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
> > + *
> > + */
> > +#include <linux/module.h>
> > +#include <linux/param.h>
> > +#include <linux/jiffies.h>
> > +#include <linux/workqueue.h>
> > +#include <linux/delay.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/power_supply.h>
> > +#include <linux/i2c.h>
> > +
> > +#include "bq27x00.h"
> > +
> > +static struct i2c_client *bq_client;
> 
> :-(
> 
> Platform device approach would eliminate need for this...

sure... that looks nice.

> > +static inline int bq27200_read(u8 reg, int *rt_value, int b_single,
> > +	struct bq27x00_device_info *di)
> > +{
> > +	struct i2c_client *client = bq_client;
> > +	struct i2c_msg msg[1];
> > +	unsigned char data[2];
> > +	int err;
> > +
> > +	if (!client->adapter)
> > +		return -ENODEV;
> > +
> > +	msg->addr = client->addr;
> > +	msg->flags = 0;
> > +	msg->len = 1;
> > +	msg->buf = data;
> > +
> > +	data[0] = reg;
> > +	err = i2c_transfer(client->adapter, msg, 1);
> > +
> > +	if (err >= 0) {
> 
> Would look better if you swap the success/fail cases:
> 
> if (err < 0) {
> 	dev_err();
> 	return err;
> }
> 
> success-code-here;

yeah, brain fart.

> > +static int __init bq27200_probe(struct i2c_client *client,
> > +		const struct i2c_device_id *id)
> > +{
> > +	struct bq27x00_device_info *di;
> > +	struct bq27x00_access_methods *bus;
> > +	int retval = 0;
> > +
> > +	di = kzalloc(sizeof(*di), GFP_KERNEL);
> > +	if (!di) {
> > +		dev_dbg(&client->dev, "could not allocate dev info's memory\n");
> > +		retval = -ENOMEM;
> > +		goto err_di;
> > +	}
> > +
> > +	bus = kzalloc(sizeof(*bus), GFP_KERNEL);
> > +	if (!bus) {
> > +		dev_dbg(&client->dev, "could not allocate bus' memory\n");
> > +		retval = -ENOMEM;
> > +		goto err_bus;
> > +	}
> > +
> > +	i2c_set_clientdata(client, di);
> > +	di->dev = &client->dev;
> > +	di->bat.name = "bq27200";
> > +	bus->read = &bq27200_read;
> > +	di->bus = bus;
> > +	bq_client = client;
> > +
> > +	bq27x00_powersupply_init(di);
> > +
> > +	retval = power_supply_register(&client->dev, &di->bat);
> > +	if (retval) {
> > +		dev_dbg(&client->dev, "could not register power_supply, %d\n",
> > +				retval);
> > +		goto err_psy;
> > +	}
> > +
> > +	INIT_DELAYED_WORK(&di->monitor_work, bq27200_work);
> > +	schedule_delayed_work(&di->monitor_work, 100);
> 
> This should be done before registering the power supply. Otherwise
> code may use the di->monitor_work before it has initialized.

that's right, good catch.

> > +static const struct i2c_device_id bq27200_id[] = {
> > +	{ "bq27200", 0 },
> 
> No need for ", 0".

doesn't the static variables automatic initialization to 0 (or NULL)
only work with the gnu style struct declaration ??

I mean:

static const struct i2c_device_id b27200_id[] = {
	{
		.name	= "bq27200",
	},
};

Anyways, I'm only following the standard used by Jean (i2c maintainer).

-- 
balbi

  reply	other threads:[~2008-10-18 22:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-17 21:00 [PATCH 0/4] bq27x00 updates Felipe Balbi
2008-10-17 21:00 ` [PATCH 1/4] power_supply: bq27x00: separate common code Felipe Balbi
2008-10-17 21:00   ` [PATCH 2/4] power_supply: bq27200: separate bq27200-specific driver Felipe Balbi
2008-10-17 21:00     ` [PATCH 3/4] power_supply: bq27200: separate bq27000-specific driver Felipe Balbi
2008-10-17 21:00       ` [PATCH 4/4] power_supply: bq27x00: get rid of old code Felipe Balbi
2008-10-18 21:46     ` [PATCH 2/4] power_supply: bq27200: separate bq27200-specific driver Anton Vorontsov
2008-10-18 22:34       ` Felipe Balbi [this message]
2008-10-18 21:36   ` [PATCH 1/4] power_supply: bq27x00: separate common code Anton Vorontsov
2008-10-18 22:29     ` Felipe Balbi
2008-10-18 23:53       ` Anton Vorontsov
2008-10-17 21:40 ` [PATCH 0/4] bq27x00 updates Anton Vorontsov
2008-10-17 21:45   ` Felipe Balbi
2008-10-18 21:16 ` Anton Vorontsov
2008-10-18 22:23   ` Felipe Balbi
2008-10-18 23:47     ` Anton Vorontsov

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=20081018223442.GV31842@frodo \
    --to=me@felipebalbi.com \
    --cc=avorontsov@ru.mvista.com \
    --cc=cbou@mail.ru \
    --cc=dwmw2@infradead.org \
    --cc=felipe.balbi@nokia.com \
    --cc=linux-omap@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