Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp330338lqe; Sat, 6 Apr 2024 03:08:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVhEjyAyuX9ihDCbuaF6VcV8hDejSz/eTY2tpZcjsijIbjVUpJH3ZoMYV5RdTzStaese4yGhSVnUV+zClS+sv4HBkW/vAbz3uiBtne+mw== X-Google-Smtp-Source: AGHT+IFTFJ8XjizgEzvMl82aWeiW5sPR+KK8ufqj7wvZrzQ2M+IsaX5ZFjSeBJ1fvC08UKEOc9Vb X-Received: by 2002:a2e:9f41:0:b0:2d8:39cf:5368 with SMTP id v1-20020a2e9f41000000b002d839cf5368mr3363297ljk.29.1712398120152; Sat, 06 Apr 2024 03:08:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712398120; cv=pass; d=google.com; s=arc-20160816; b=H4Q1cEldhMIULlSDyUror9VGepIq3kX5nkb7fXorHAC/OBv27D2ZT+lUfmATLJzUJT 5oRfzOBQ4YD7m0BPX5nLZXyOcIPq3myTX5iPH7Trm3r3+8xakUAAAuEOyOD4VYj+f3km a9GIiU0kC/CWKqS8giPFL7P7zZdQEh2LBo859lBW/1SkiC6UxPoorD7ppNub4vkUo3M2 9e1Pas7RbPYS6kGdwdUAmwDZq1aJztexvthTlw9c7IIoQKGGUTQ7pXqIG3zFCIlIWCjI +OwsRkOWndCSy9T0j2Ux70pRMVONxGp/g6nZWCbls9a+oI/QYQz0eCgMaF6O2OBDTucv iRZQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=UR4gnp4ayupyCNcWxaHSMlJFT8UXL1wnVzO5mlCXlPM=; fh=34iJl3O08/fXvzEL1h8BcaJ2lYlEuNIPtnRfTWWIWrc=; b=KVpEWnA2nm7BxDX1bSYk/9zsjgxHfkSUsXri4TjtA/ZfMCD8szWdUVw4KHOVGO0S0O YaIUWHw5Xadjop1tKQPnobH5l7I6PwFRcamybfGsgIRcXt9Y5XdbtNFddUswbv5Gp7fR iR7SUfYt7gZVbFQ1N0t3cosDlFI3v3WObLkbcyfZY7CQSAvu3Kozim671gobn3l4Looj 8U+HU0PqLCPs6eStOHYhNIMpECL4/l9N+CXk240N2tsFG8abC+1FvprvtaHoFwLYHxYu EhtQ6tii9Gm+qTkLf/pIE9ns2aqb0LAWUwXCmXNdfNpw2E3BPVnEP4Tlxg6QfM18Pr0r BfgQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NXjxwyXD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-133885-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133885-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id di13-20020a170906730d00b00a51947c768esi1689902ejc.42.2024.04.06.03.08.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Apr 2024 03:08:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-133885-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NXjxwyXD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-133885-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133885-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D946D1F21A6A for ; Sat, 6 Apr 2024 10:08:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D9B925624; Sat, 6 Apr 2024 10:08:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NXjxwyXD" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7182817C8B; Sat, 6 Apr 2024 10:08:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712398111; cv=none; b=QIYNM1KPIQCgmk/IIH4khwpKQ9XUx7QDXU6Y3RC6C1Ympv5wcqDHucxHPU9eV2jtffvRWYneg3v1iYmf1mAQRWjtdRt3Q7q/YAtXp1LR+6TYhQmyH4VwNK5Bc3SieQgUu2HHO4DJGaq1riI8wIB6U1Psu2J9hptGvKLXY2pgCUg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712398111; c=relaxed/simple; bh=Z6PBdPhnDe/NoeFHmiy0yxTrTTqhT2vxjT3G/87Rh3g=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FMtf16UYHEoTPrUG0kcO5hrVQP6szWx4HocKLkPbjFVnNbirWTU8DsUgPuzu/YiVWH/ThxDB8iIHn+oPlezwULGdyKqQ3Fvikyb6C50ILIDGcpDcoQMfMLsC8OYBJvy2HVfZNplyYJxr9FaSJsN+Qo3y64tBGnGGvNijCCrw+GY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NXjxwyXD; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB1E4C433F1; Sat, 6 Apr 2024 10:08:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712398111; bh=Z6PBdPhnDe/NoeFHmiy0yxTrTTqhT2vxjT3G/87Rh3g=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NXjxwyXDVIcZy8q73YoR2uJHtzrPxatWvLBkDmrM9EbgJiLw7LZg5PKeJ8HN8rhzc MOYgcssIUVDadAb3nCua6bAK0aXPrHxZTNP4i6lWKWOLDVOjBZREISyUqHQR8PtL47 UyH+0OzQW6H8WFf2VJ+WwrgE04Lq1kIgwFqI02wjkbu8HOBJ9dFuprWc205I0ENwmO apxZLRsJM0xxt3vwmqE7tiaK1r3FDCoJONixS4m5QbmNQ3x7m3w49xTaV5R0CSuEyu FHvz52fJDKe7Ds2sv7cqHyDANh0yW8qnrJFqoxrW4vPeeyepEqP/rdpwZFuj+UeRqR JZED8C/abbwtw== Date: Sat, 6 Apr 2024 11:08:17 +0100 From: Jonathan Cameron To: HAEMMERLE Thomas Cc: "joel@jms.id.au" , GEO-CHHER-bsp-development , Eddie James , Lars-Peter Clausen , "linux-iio@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] iio: pressure: dps310: support negative pressure and temperature values Message-ID: <20240406110817.2c2be48d@jic23-huawei> In-Reply-To: <34c1c26a-4787-4713-8c7d-040732a18092@leica-geosystems.com> References: <20240327084937.3801125-1-thomas.haemmerle@leica-geosystems.com> <20240328133421.1844a83c@jic23-huawei> <34c1c26a-4787-4713-8c7d-040732a18092@leica-geosystems.com> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit > >> -static int dps310_get_pres_k(struct dps310_data *data) > >> +static int dps310_get_pres_k(struct dps310_data *data, int *val) > >> { > >> - int rc = dps310_get_pres_precision(data); > >> + int rc; > >> > >> - if (rc < 0) > >> + rc = dps310_get_pres_precision(data, val); > >> + if (rc) > >> return rc; > >> > >> - return scale_factors[ilog2(rc)]; > >> + *val = scale_factors[ilog2(*val)]; > > This only just went to the effort of 2^val, so why not skip that step and > > pull the BIT() section out to read_pressure() where we do want that form. > > You will need an extra local variable at that call site I think, but > > in general it is a useful additional simplification of the code. > > I'm not sure if I get you correct, as this function is not directly > called in `read_pressure`: > You suggest dropping this function at all, call > `dps310_get_pres_precision` directly in `dps310_calculate_pressure` and > move the lookup of the compensation scale factor there? More simply avoid _get_pres_precision returning a value that is in the form that requires us to immediately undo the BIT() logic at the end of that function. One way to do that is to just call the regmap_read() directly here. > > >> + > >> + return 0; > >> } > >> > >> -static int dps310_get_temp_k(struct dps310_data *data) > >> +static int dps310_get_temp_k(struct dps310_data *data, int *val) > >> { > >> - int rc = dps310_get_temp_precision(data); > >> + int rc; > >> > >> - if (rc < 0) > >> + rc = dps310_get_temp_precision(data, val); > >> + if (rc) > >> return rc; > >> > >> - return scale_factors[ilog2(rc)]; > >> + *val = scale_factors[ilog2(*val)]; > > As above. > > Based on my interpretation above: > For `dps310_get_temp_k` it would require to move the lookup of the > compensation scale factor to `dps310_calculate_pressure` and > `dps310_calculate_temp`. > Maybe this would simplify the code, but it would make it harder to read. Just call rc = regmap_read(data->regmap, DPS310_TMP_CFG, val); here and use *val = scale_factors[val & GENMASK(2, 0)]; here which I think ends up with the same value. > > > Thomas > > >> + > >> + return 0; > >> } > > >