From patchwork Sun Apr 16 22:14:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 83941 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1797495vqo; Sun, 16 Apr 2023 17:14:24 -0700 (PDT) X-Google-Smtp-Source: AKy350b/ea5JJ6kOzCjF2MaEPxmqOmDvtw0hP6R+M4v/hcGk67efLGgE7MJb+UoVC0lbUUH3Whva X-Received: by 2002:a05:6a20:4694:b0:dc:925f:62f1 with SMTP id el20-20020a056a20469400b000dc925f62f1mr11898861pzb.6.1681690464068; Sun, 16 Apr 2023 17:14:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681690464; cv=none; d=google.com; s=arc-20160816; b=PdlaLmnmCpx8aVz+KBRsQsIiSlA/TbsjBsp/HtSPjkpgGZ9Vmy72C/gjw5jrSAta/l Y5pwTc/X4zpG9yPZeOdORsr9gBFxy944tpT1Kg1inuAeLqX/u/SZKOLdYFHoT67N87OT FyEpbkkwvEkx4s3TQmgt8KuYn89IQDKOP9kVC1Hx8hGnTDw/CTiPR4n3lGAN9nNzKPzI BJ82LWoo48OHDPK+tMYe6HFuWzSAOjajg//+QBJ7dFLoUaJBf4ZGWLc1wxXDa3XFdq6u 4XW7FKlwMzAMm1CCgGawAh0Zua3tvtqbveu6/r3aFOSvVs7hr2VPH+6AxSMkrA/3eL+w nUog== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=f4Jh1YKOoXycqM/ekvBOa/gB5r5j8s3SNJI5ciLqyyU=; b=JhiYUhNJCgGaAugqqTdrs6m0KWAaZVb6TzbhnWS3iwDVi3E7cSNHQfxTnvaC4ggdqI qru4xycV4tJP1IuNZDtbHNSY9QH+ecmJiScHRmkBh4+oii/eZjeAcERK8VJ1FJYODYZS 4ErLDOeMfzxZjeTDEBoDQc8btmWPXkQI7RQ0WbachnCiyDnfGH52kmvcu/KtzUeU2A07 pE5F+f+lG+shFdL62Q0wOEP+j0EK/E2J6s6Xy/FUSSG8RON6TLN1gu1sxc4BLVJ9KEvk uJZ78fOxU645Spe4PrQhRJ0W+DRb2gjgHa8IQuxWxawne/CdNl01IW0tUROgXz1VEevc fHGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@orange.fr header.s=t20230301 header.b=WfyEaNEI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x28-20020aa7941c000000b0062a4f62c018si10284883pfo.10.2023.04.16.17.14.09; Sun, 16 Apr 2023 17:14:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@orange.fr header.s=t20230301 header.b=WfyEaNEI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229997AbjDPWOv (ORCPT + 99 others); Sun, 16 Apr 2023 18:14:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbjDPWOt (ORCPT ); Sun, 16 Apr 2023 18:14:49 -0400 Received: from smtp.smtpout.orange.fr (smtp-27.smtpout.orange.fr [80.12.242.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3E2F2126 for ; Sun, 16 Apr 2023 15:14:47 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id oAdvpfmXF7JnhoAdwpmfbm; Mon, 17 Apr 2023 00:14:45 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=orange.fr; s=t20230301; t=1681683285; bh=f4Jh1YKOoXycqM/ekvBOa/gB5r5j8s3SNJI5ciLqyyU=; h=From:To:Cc:Subject:Date; b=WfyEaNEIr5MFNeyZw6p+zChJC8j4ilHvVGniPI6rCLbM1VhXcmU2psKUNWjjGnmpf 5cFh3OlgrZYsfaIVVSvLt2S9qOgEm/Y8n+FKPjYELR3dkB98/IwcfB1/VRnlIpzYai rlRQETn2jkZQPjTj9gVy0w/dlgWX6Zb7O53KiaKHjnYKElLd9xdSIpSuZr7YnOlzVs MnkRg7MYy+DxqoR4CU9SUG+BYoBTZaae9ZRRmXtaLJreNRdPIQij8J9dQiuVxxZ6AC VpJZ31qUQEcDetEzYF1hc+TPD+oNCd3gtKxPabN9a+sdijGrzIyVNqKrxRLtW2VdMs zrBg1muOmQcpA== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 17 Apr 2023 00:14:45 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Laurent Pinchart , Manivannan Sadhasivam , Mauro Carvalho Chehab , Sakari Ailus Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-media@vger.kernel.org Subject: [PATCH] media: i2c: imx296: Fix error handling while reading temperature Date: Mon, 17 Apr 2023 00:14:42 +0200 Message-Id: <827f94730c85b742f9ae66209b383a50ca79ec43.1681683246.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763380260246632597?= X-GMAIL-MSGID: =?utf-8?q?1763380260246632597?= If imx296_read() returns an error, its returned value is a negative value. But because of the "& IMX296_TMDOUT_MASK" (i.e. 0x3ff), 'tmdout' can't be negative. So the error handling does not work as expected and a wrong value is used to compute the temperature. Apply the IMX296_TMDOUT_MASK mask after checking for errors to fix it. Fixes: cb33db2b6ccf ("media: i2c: IMX296 camera sensor driver") Signed-off-by: Christophe JAILLET --- drivers/media/i2c/imx296.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/imx296.c b/drivers/media/i2c/imx296.c index 4f22c0515ef8..c3d6d52fc772 100644 --- a/drivers/media/i2c/imx296.c +++ b/drivers/media/i2c/imx296.c @@ -922,10 +922,12 @@ static int imx296_read_temperature(struct imx296 *sensor, int *temp) if (ret < 0) return ret; - tmdout = imx296_read(sensor, IMX296_TMDOUT) & IMX296_TMDOUT_MASK; + tmdout = imx296_read(sensor, IMX296_TMDOUT); if (tmdout < 0) return tmdout; + tmdout &= IMX296_TMDOUT_MASK; + /* T(°C) = 246.312 - 0.304 * TMDOUT */; *temp = 246312 - 304 * tmdout;