Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp3288764rwe; Sun, 16 Apr 2023 16:37:45 -0700 (PDT) X-Google-Smtp-Source: AKy350Y3HDcdXLQoPVsMAaVWBy4KEo3SePbJ+Ql7/CgBmmtJLTzSEdze2bEyz1HWDfrJNG7+RSG9 X-Received: by 2002:a17:90a:a787:b0:246:865d:419a with SMTP id f7-20020a17090aa78700b00246865d419amr19144015pjq.6.1681688264917; Sun, 16 Apr 2023 16:37:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681688264; cv=none; d=google.com; s=arc-20160816; b=FmINIyfEJTsDe46MVh84mD+uLTThuyHzz8kqGX83KY3hJEbrcgdSbeyz318Kub477w Xcp7mZpFQLgZnyRxgas81JClAD0DOKkHsnmdWYvCXawKsfG9VxItqh/8X1xeiUq2hdlH L0jLxNkuxZvds0/PGtqHZGOnXjSEmlcrUZHEpOJbh+jvgS1b2nAubpltrbFWpgCiBk0k Mn56c4ogjr58ZlpTtsF0/4aLLTLHjb5jUOZCer5DWXICPHIjCi3GdguQTfXPrbPLv5Fw Ak9vIEExqYusX2RFEkbpVJzddZok5X933oJXIe0BGT/bDl356m7XX7sfMElG9YyP8NZx C/XA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n3-20020a170902e54300b001a1e867f287si11205778plf.460.2023.04.16.16.37.33; Sun, 16 Apr 2023 16:37:44 -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 S229995AbjDPWOu (ORCPT + 99 others); Sun, 16 Apr 2023 18:14:50 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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; -- 2.34.1