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]
Message-ID: <20190107153542.GD14782@localhost>
Date:   Mon, 7 Jan 2019 16:35:42 +0100
From:   Johan Hovold <johan@...nel.org>
To:     Tomasz Duszynski <tduszyns@...il.com>
Cc:     linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org,
        devicetree@...r.kernel.org
Subject: Re: [PATCH 1/3] iio: chemical: add support for Plantower PMS7003
 sensor

On Sun, Jan 06, 2019 at 06:16:12PM +0100, Tomasz Duszynski wrote:
> Add support for Plantower PMS7003 particulate matter sensor.
> 
> Signed-off-by: Tomasz Duszynski <tduszyns@...il.com>

> +static int pms7003_do_cmd(struct pms7003_state *state, u8 cmd)
> +{
> +	/*
> +	 * commands have following format:
> +	 *
> +	 * +------+------+-----+------+-----+-----------+-----------+
> +	 * | 0x42 | 0x4d | cmd | 0x00 | arg | cksum msb | cksum lsb |
> +	 * +------+------+-----+------+-----+-----------+-----------+
> +	 */
> +	u8 tmp[PMS7003_CMD_LENGTH] = { PMS7003_MAGIC_MSB, PMS7003_MAGIC_LSB };
> +	int ret, n = 2;
> +	u16 checksum;
> +
> +	switch (cmd) {
> +	case CMD_WAKEUP:
> +		tmp[n++] = 0xe4;
> +		tmp[n++] = 0x00;
> +		tmp[n++] = 0x01;
> +		break;
> +	case CMD_ENTER_PASSIVE_MODE:
> +		tmp[n++] = 0xe1;
> +		tmp[n++] = 0x00;
> +		tmp[n++] = 0x00;
> +		break;
> +	case CMD_READ_PASSIVE:
> +		tmp[n++] = 0xe2;
> +		tmp[n++] = 0x00;
> +		tmp[n++] = 0x00;
> +		break;
> +	case CMD_SLEEP:
> +		tmp[n++] = 0xe4;
> +		tmp[n++] = 0x00;
> +		tmp[n++] = 0x00;
> +		break;
> +	}
> +
> +	checksum = pms7003_calc_checksum(tmp, n);
> +	put_unaligned_be16(checksum, tmp + n);
> +	n += PMS7003_CHECKSUM_LENGTH;
> +
> +	ret = serdev_device_write(state->serdev, tmp, n, PMS7003_TIMEOUT);
> +	if (ret)
> +		return ret;

Beginning with 5.0, serdev_device_write() returns the number of bytes
written before timeout (or being interrupted) so you need to check
against < n here.

Johan

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ