Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3743004imu; Mon, 7 Jan 2019 08:39:19 -0800 (PST) X-Google-Smtp-Source: ALg8bN68RIquXTj9wh06cuwYPlVodysXZErlnLgFqtSyzenHnNYLzPomiOFtDymmzcSYMj5CYXwW X-Received: by 2002:a17:902:7201:: with SMTP id ba1mr61625271plb.105.1546879159743; Mon, 07 Jan 2019 08:39:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546879159; cv=none; d=google.com; s=arc-20160816; b=v2aU/udZLFaEU4K4c5V4Txp3bzWnbz4RUKeYD4+YwOIBy9rRD5OUoiirMHQzGxxD97 di2svwwvAcsK3oRhwVCsSsM9IfA5HHJHajUMIwoLSDHiCRzEb9WG2gI6Clv+LNxaa6wa XOxDEqI4S6UqNO3ECxrknj0HcgAbvqHLGgtwIV4IbCiFUzomg4Td7tcrraFf/cKHemlQ CdQJIlKq1cT5M87yuBD0I/DdMhTmD12gpEs4uwu4XF0CeZJMfo/fatO0diBqA64hD5n1 +ZiOUIVxQ2okyK9TTfjo4RgZiQBqxvbEdBhBxdAsRkH748lDDRh5OKaL25VIo3vgXLRT i71g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=lrHZWH2gp5dQS5oNDLNu8kQj0Oa5+63+557GDr1n0hE=; b=RXwhzYjxi6CszYo3rPbai1l5IJLNQN7H4KQ1Ew9exuzHnMJk1Jugj0DFqB0tq4xfbr y+/OJEt+a+GaAqXv9jLtpXHmpPGa/mYYgLHLGHdkkv2fzRIsNM6Apj6IMbhHr4E+86lz 9Npag10SwOs4Op2dmzeZ3nTpCnR75KERGo7RmlGccm2HtAdTpdP7V2OpdsB8X2i0z2WJ RDwbUNkrsWud7yvoXb3lE3hUTiZXSEUsm4JKCVSStGM7gSnFjki5+RUWaW6scuc45X4N J0FasvhnQMtRqRgvCGxUDzr9xR/oOZZ9p4oCXQyrEAZzUb4FxMiLC030MWF8+QU2gpPc 63Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=BmHwUq5d; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r39si15551063pld.434.2019.01.07.08.39.04; Mon, 07 Jan 2019 08:39:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=BmHwUq5d; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730021AbfAGPfp (ORCPT + 99 others); Mon, 7 Jan 2019 10:35:45 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:43441 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726873AbfAGPfp (ORCPT ); Mon, 7 Jan 2019 10:35:45 -0500 Received: by mail-lj1-f195.google.com with SMTP id q2-v6so666238lji.10; Mon, 07 Jan 2019 07:35:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=lrHZWH2gp5dQS5oNDLNu8kQj0Oa5+63+557GDr1n0hE=; b=BmHwUq5dVKd214oJW8N41qc4iqMh0/89X5rgEBP3ttf6TCd8+/IyfeeIpxX0vwJwBt vtcjoB6qcJo5V4h0XvfvneavnhQOlb3sGiy7wzsqeTLVzBWW1TdJxuOMRmKZcfvUmkjq dalKULxg6QaQX/DNiitM7sStnPtb5tiblgSiT9PaDCjR/jwr2Oqc7hK3pWH+/AMp8Llg GZpyNgTHsh8/wftGea9ao6Wt2KfsFU/WsuxjKCuT0M1mgbLyquVR8+Uu2d35fwXGKyhl H5EYNQ8hk/zjljml0UXL4P+E8fhg4DU7W69kRNUkUJNi/DSusRbhRie0kqdKLHwiPFPx TtFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=lrHZWH2gp5dQS5oNDLNu8kQj0Oa5+63+557GDr1n0hE=; b=FJmSF6p5IEMXnv0oNLaocrj6qM6kAz3D6k8ZbWgiw8lle0qRBEORJgEL8T6xySC7CF 6pYeKvBtBZygGfGJJxkWvLmABMRI+YQKVIwZiFVjzoFYJmGbqtBeUpairS31UGVRJ+E3 XQtDeDwAUIAQ/aJT40uj3WnZi3ZvEKhEUsmksmYFp6bOLsAQJqjWR6bgK/c3JH6TUi1n R3KH7JLR6mKMFdM5J7+EtHvVX/kHUccPEMibWUXJe6sy92FlMjKbmtg4mBIoxikENIGg 0Wl+ccFfUbWNoBeipu++ghFU2RJsGSBRf9i+UjbHUoJvXYmCU7jmNsJ05fGDLtR1iLha c2dg== X-Gm-Message-State: AA+aEWY9AqpaqBFmqQUvokjXuSY0Z++O0OeGFEdaF1Ye18tumcqnxmXi bjAXaPD4q5b8HBKN5xqc4LE= X-Received: by 2002:a2e:868c:: with SMTP id l12-v6mr38436644lji.90.1546875342439; Mon, 07 Jan 2019 07:35:42 -0800 (PST) Received: from xi.terra (c-74bee655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.190.116]) by smtp.gmail.com with ESMTPSA id x16sm12378597lff.26.2019.01.07.07.35.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Jan 2019 07:35:41 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.91) (envelope-from ) id 1ggWwI-0003YS-0a; Mon, 07 Jan 2019 16:35:42 +0100 Date: Mon, 7 Jan 2019 16:35:42 +0100 From: Johan Hovold To: Tomasz Duszynski Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: Re: [PATCH 1/3] iio: chemical: add support for Plantower PMS7003 sensor Message-ID: <20190107153542.GD14782@localhost> References: <20190106171614.12615-1-tduszyns@gmail.com> <20190106171614.12615-2-tduszyns@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190106171614.12615-2-tduszyns@gmail.com> User-Agent: Mutt/1.11.1 (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > +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