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  linux-cve-announce  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:	Sun, 10 Apr 2016 12:07:24 +0100
From:	Jonathan Cameron <jic23@...nel.org>
To:	Slawomir Stepien <sst@...zta.fm>, knaack.h@....de, lars@...afoo.de,
	pmeerw@...erw.net
Cc:	linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] iio: potentiometer: add driver for Maxim Integrated
 DS1803

On 09/04/16 12:12, Slawomir Stepien wrote:
> On Apr 08, 2016 23:27, Slawomir Stepien wrote:
>> +static int ds1803_read_raw(struct iio_dev *indio_dev,
>> +			    struct iio_chan_spec const *chan,
>> +			    int *val, int *val2, long mask)
>> +{
>> +	struct ds1803_data *data = iio_priv(indio_dev);
>> +	int pot = chan->channel;
>> +	int ret;
>> +	u16 result;
>> +
>> +	switch (mask) {
>> +	case IIO_CHAN_INFO_RAW:
>> +		ret = i2c_master_recv(data->client, (char *)&result,
>> +				indio_dev->num_channels);
>> +		if (ret < 0)
>> +			return ret;
>> +
>> +		/* Get bits for given pot */
>> +		*val = (pot == 0 ? result & 0xff : result >> 8);
>> +		return IIO_VAL_INT;
>> +
>> +	case IIO_CHAN_INFO_SCALE:
>> +		*val = 1000 * data->cfg->kohms;
>> +		*val2 = DS1803_MAX_POS;
>> +		return IIO_VAL_FRACTIONAL;
>> +	}
>> +
>> +	return -EINVAL;
>> +}
> 
> Or maybe this is more clean?
> 
> static int ds1803_read_raw(struct iio_dev *indio_dev,
> 			    struct iio_chan_spec const *chan,
> 			    int *val, int *val2, long mask)
> {
> 	struct ds1803_data *data = iio_priv(indio_dev);
> 	int pot = chan->channel;
> 	int ret;
> 	unsigned char result[indio_dev->num_channels];
I'd use  u8 to make it of an explicit size but otherwise this is indeed
a little bit cleaner.

> 
> 	switch (mask) {
> 	case IIO_CHAN_INFO_RAW:
> 		ret = i2c_master_recv(data->client, result,
> 				indio_dev->num_channels);
> 		if (ret < 0)
> 			return ret;
> 
> 		*val = result[pot];
> 		return IIO_VAL_INT;
> 
> 	case IIO_CHAN_INFO_SCALE:
> 		*val = 1000 * data->cfg->kohms;
> 		*val2 = DS1803_MAX_POS;
> 		return IIO_VAL_FRACTIONAL;
> 	}
> 
> 	return -EINVAL;
> }
> 
> What do you think?
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ