Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1030949pxy; Sun, 1 Aug 2021 10:01:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVCY/G43FqZlgdb+LNCtAQ63NazmeR0wpVIwzZGkEn6q5FxEL5eXpL7w42pvRZ4mO1lbBf X-Received: by 2002:a05:6402:50d4:: with SMTP id h20mr14833001edb.7.1627837297003; Sun, 01 Aug 2021 10:01:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627837296; cv=none; d=google.com; s=arc-20160816; b=rl/vnGYAIM5VRGDJDcscmdVHuZ7++VfeR524ZpiLUQsDP6NbVHgIIv6PzGTOfiN5nk a8fsNXQooTLgcO0wHze0oNp+C60clA/AoZFTqVa1XY9+1Mo57gARzMfsYlBAcQb+0O0i xis5sfqJ+BTmWcsXoqT/D5glUuHa7HV26U2SJr4QnHLdNjYHa+G9J7SEtBGtj8XpwXfK hS2Ccnym7KwePnYiAL8w/LzuW4OSFMLKapFnqbh7Y3azLFMX+rIzjX4L1Pc1tCEDOnMj j1SbxnngFidmpVCHN6JuqQ+WNwdcXQVS3avlEE+QE6pXRgcVaYBWo0pX/p4vvQOpdNuC +0bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=G6edRDfbCwudZp/yU1AatbAdCjtur894OrrCvSoaB0E=; b=LxlIasYd0EsNs9ge+lu5uYHT0t3+vwGdsFCnzk+xa13UtFUUYYuszN+MjpNIS7cAj0 dmrBV2MdIaIsQve37rnLqQRtyWuOKnvDKBDJR+ah9C9TZ5nO1SnUAfN23EW96lJFfV35 oI2kSsYinmQzCi29JiDCVxX3WZt/nI9VlTnwz/ZifyNfjHiSruqh65AVOV1OofuNIJHN ILfB+Klpuh+ZThib4mgVZHMMmHgXCH+/B6pw1BPPQOCCRG7MR/hIXSCwdl0dsNH7DySK lHVPj0BTxfI4tDb0uzWw78mey1TcF7XqBELLQvaQKGhZcjsCOb1gCU+/ROZa1yQggJk1 o3PQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bd27si7390583edb.219.2021.08.01.10.01.11; Sun, 01 Aug 2021 10:01:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229675AbhHAQ6p (ORCPT + 99 others); Sun, 1 Aug 2021 12:58:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:45920 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229575AbhHAQ6p (ORCPT ); Sun, 1 Aug 2021 12:58:45 -0400 Received: from jic23-huawei (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A7B3960EB5; Sun, 1 Aug 2021 16:58:31 +0000 (UTC) Date: Sun, 1 Aug 2021 18:01:11 +0100 From: Jonathan Cameron To: Guenter Roeck Cc: Andreas Klinger , devicetree@vger.kernel.org, linux-iio@vger.kernel.org, Rob Herring , Jonathan Cameron , Jiri Kosina , Chris Packham , Slawomir Stepien , Krzysztof Kozlowski , Alexandre Belloni , Vadim Pasternak , Alexandru Ardelean , linux-kernel@vger.kernel.org, Lars-Peter Clausen , Tomasz Duszynski Subject: Re: [PATCH 2/2] iio: chemical: Add driver support for sgp40 Message-ID: <20210801180111.28a1c4d1@jic23-huawei> In-Reply-To: <42e31edc-445c-06ac-dd3a-80db1b439996@roeck-us.net> References: <20210727163517.GA3468@arbad> <20210731173928.08d6812f@jic23-huawei> <42e31edc-445c-06ac-dd3a-80db1b439996@roeck-us.net> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 31 Jul 2021 11:06:25 -0700 Guenter Roeck wrote: > On 7/31/21 9:39 AM, Jonathan Cameron wrote: > > On Tue, 27 Jul 2021 18:35:19 +0200 > > Andreas Klinger wrote: > > > >> sgp40 is a gas sensor used for measuring the air quality. > >> > >> This driver is reading the raw resistance value which can be passed to > >> a userspace algorithm for further calculation. > >> > >> The raw value is also used to calculate an estimated absolute voc index > >> in the range from 0 to 500. For this purpose the raw_mean value of the > >> resistance for which the index value is 250 might be set up as a > >> calibration step. > >> > >> Compensation of relative humidity and temperature is supported and can > >> be used by writing to device attributes of the driver. > >> > >> There is a predecesor sensor type (sgp30) already existing. This driver > >> module was not extended because the new sensor is quite different in its > >> i2c telegrams. > >> > >> Signed-off-by: Andreas Klinger > > > > Hi Andreas, > > > > Non standard ABI in here, so we are missing documentation in Documentation/ABI/testing/sysfs-bus-iio-* > > > > Otherwise a few suggestions inline. > > > > Thanks, > > > > Jonathan > > > > > >> --- > [ ... ] > > >> +static int sgp40_read_raw(struct iio_dev *indio_dev, > >> + struct iio_chan_spec const *chan, int *val, > >> + int *val2, long mask) > >> +{ > >> + struct sgp40_data *data = iio_priv(indio_dev); > >> + int ret; > >> + u16 raw; > >> + int voc; > >> + > >> + switch (mask) { > >> + case IIO_CHAN_INFO_RAW: > >> + mutex_lock(&data->lock); > >> + ret = sgp40_measure_raw(data, &raw); > >> + if (ret) { > >> + mutex_unlock(&data->lock); > >> + return ret; > >> + } > >> + *val = raw; > >> + ret = IIO_VAL_INT; > >> + mutex_unlock(&data->lock); > >> + break; > >> + case IIO_CHAN_INFO_PROCESSED: > >> + mutex_lock(&data->lock); > >> + ret = sgp40_measure_raw(data, &raw); > >> + if (ret) { > >> + mutex_unlock(&data->lock); > >> + return ret; > >> + } > >> + ret = sgp40_calc_voc(data, raw, &voc); > >> + if (ret) { > >> + mutex_unlock(&data->lock); > >> + return ret; > >> + } > >> + *val = voc; > >> + ret = IIO_VAL_INT; > >> + mutex_unlock(&data->lock); > > > > You are holding the lock longer than needed - it would be good > > to reduce this, hopefully removing the need for unlocking separately > > in each of the error paths. > > > >> + break; > >> + default: > >> + return -EINVAL; > >> + } > >> + > >> + return ret; > > > > Drop this as you can't get here. > > > > Are you sure ? I see several "break;" above. Doh! In that case, return directly where it has break above so we don't need to go see if anything else happens in those paths. > > Guenter