lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 5 Jan 2015 16:20:02 +0200
From:	Daniel Baluta <daniel.baluta@...el.com>
To:	Joe Perches <joe@...ches.com>
Cc:	Daniel Baluta <daniel.baluta@...el.com>,
	Kevin Tsai <ktsai@...ellamicro.com>,
	Wolfram Sang <wsa@...-dreams.de>,
	Rob Herring <robh+dt@...nel.org>,
	Pawel Moll <pawel.moll@....com>,
	Mark Rutland <mark.rutland@....com>,
	Ian Campbell <ijc+devicetree@...lion.org.uk>,
	Kumar Gala <galak@...eaurora.org>,
	Jonathan Cameron <jic23@...nel.org>,
	Hartmut Knaack <knaack.h@....de>,
	Lars-Peter Clausen <lars@...afoo.de>,
	Peter Meerwald <pmeerw@...erw.net>,
	Grant Likely <grant.likely@...aro.org>,
	Andrew Morton <akpm@...ux-foundation.org>,
	"David S. Miller" <davem@...emloft.net>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Mauro Carvalho Chehab <mchehab@....samsung.com>,
	Antti Palosaari <crope@....fi>,
	Archana Patni <archana.patni@...ux.intel.com>,
	linux-i2c@...r.kernel.org, devicetree@...r.kernel.org,
	"linux-iio@...r.kernel.org" <linux-iio@...r.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH V1 1/1] iio: Added Capella cm3232 ambient light sensor driver.

On Mon, Jan 5, 2015 at 3:09 PM, Joe Perches <joe@...ches.com> wrote:
> On Mon, 2015-01-05 at 12:51 +0200, Daniel Baluta wrote:
>> On Thu, Jan 1, 2015 at 2:10 AM, Kevin Tsai <ktsai@...ellamicro.com> wrote:
>> > CM3232 is an advanced ambient light sensor with I2C protocol interface.
>> > The I2C slave address is internally hardwired as 0x10 (7-bit).  Writing
>> > to configure register is byte mode, but reading ALS register requests to
>> > use word mode for 16-bit resolution.
>>
>> This looks good to me.  Few comments inline.
> []
>> > diff --git a/drivers/iio/light/cm3232.c b/drivers/iio/light/cm3232.c
> []
>> > +/**
>> > + * cm3232_reg_init() - Initialize CM3232 registers
>> > + * @chip:      pointer of struct cm3232.
>> > + *
>> > + * Initialize CM3232 ambient light sensor register to default values.
>> > + *
>> > +  Return: 0 for success; otherwise for error code.
>> > + */
>> > +static int cm3232_reg_init(struct cm3232_chip *chip)
>> > +{
>> > +       struct i2c_client *client = chip->client;
>> > +       struct cm3232_als_info *als_info;
>> > +       s32 ret;
>> > +
>> > +       /* Identify device */
>> > +       ret = i2c_smbus_read_word_data(client, CM3232_REG_ADDR_ID);
>> > +       if (ret < 0)
>> > +               return ret;
>> > +       if ((ret & 0xFF) != 0x32)
>> > +               return -ENODEV;
>> > +
>> > +       /* Disable and reset device */
>> > +       chip->regs_cmd = CM3232_CMD_ALS_DISABLE | CM3232_CMD_ALS_RESET;
>> > +       ret = i2c_smbus_write_byte_data(client, CM3232_REG_ADDR_CMD,
>> > +                               chip->regs_cmd);
>> > +       if (ret < 0)
>> > +               return ret;
>> > +
>> > +       /* Initialization */
>> > +       als_info = chip->als_info = &cm3232_als_info_default;
>> > +       chip->regs_cmd = CM3232_CMD_DEFAULT;
>> > +
>> > +       /* Configure register */
>> > +       ret = i2c_smbus_write_byte_data(client, CM3232_REG_ADDR_CMD,
>> > +                               chip->regs_cmd);
>>
>> You could directly return i2c_smbus_write_byte_data(..).
>
> Sometimes it's better to return a specific value
> for the error instead of depending on correctness
> of all the indirect functions in the call chain.
>
> In this case, all the smbus_xfer functions must
> return 0 on success.  Do they?

Yes.

http://lxr.free-electrons.com/source/drivers/i2c/i2c-core.c#L2845

>
> Inspecting the codebase for correctness or not
> depending on that correctness is sometimes better
> to avoid doing.

You have a valid point. Anyhow, AFAIK the code from IIO
prefers a direct return.

Also, I guess kbuild test robot will complain about it, like here:

http://marc.info/?l=linux-kernel&m=141963536230419&w=2

thanks,
Daniel.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists