* [PATCH] media: i2c: imx296: Fix error handling while reading temperature
@ 2023-04-16 22:14 Christophe JAILLET
2023-04-17 5:30 ` Laurent Pinchart
0 siblings, 1 reply; 3+ messages in thread
From: Christophe JAILLET @ 2023-04-16 22:14 UTC (permalink / raw)
To: Laurent Pinchart, Manivannan Sadhasivam, Mauro Carvalho Chehab,
Sakari Ailus
Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-media
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 <christophe.jaillet@wanadoo.fr>
---
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] media: i2c: imx296: Fix error handling while reading temperature
2023-04-16 22:14 [PATCH] media: i2c: imx296: Fix error handling while reading temperature Christophe JAILLET
@ 2023-04-17 5:30 ` Laurent Pinchart
2023-04-17 10:00 ` Sakari Ailus
0 siblings, 1 reply; 3+ messages in thread
From: Laurent Pinchart @ 2023-04-17 5:30 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Manivannan Sadhasivam, Mauro Carvalho Chehab, Sakari Ailus,
linux-kernel, kernel-janitors, linux-media
Hi Christophe,
Thank you for the patch.
On Mon, Apr 17, 2023 at 12:14:42AM +0200, Christophe JAILLET wrote:
> 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 <christophe.jaillet@wanadoo.fr>
Dan Carpenter has submitted the same fix in
https://lore.kernel.org/linux-media/Y%2FYf19AE78jn5YW7@kili/. Sakari,
could you please pick it up ?
> ---
> 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;
>
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] media: i2c: imx296: Fix error handling while reading temperature
2023-04-17 5:30 ` Laurent Pinchart
@ 2023-04-17 10:00 ` Sakari Ailus
0 siblings, 0 replies; 3+ messages in thread
From: Sakari Ailus @ 2023-04-17 10:00 UTC (permalink / raw)
To: Laurent Pinchart
Cc: Christophe JAILLET, Manivannan Sadhasivam, Mauro Carvalho Chehab,
linux-kernel, kernel-janitors, linux-media
Hi Laurent,
On Mon, Apr 17, 2023 at 08:30:59AM +0300, Laurent Pinchart wrote:
> Hi Christophe,
>
> Thank you for the patch.
>
> On Mon, Apr 17, 2023 at 12:14:42AM +0200, Christophe JAILLET wrote:
> > 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 <christophe.jaillet@wanadoo.fr>
>
> Dan Carpenter has submitted the same fix in
> https://lore.kernel.org/linux-media/Y%2FYf19AE78jn5YW7@kili/. Sakari,
> could you please pick it up ?
Oops, thanks for notifying me. This slipped from my hands somehow. It's in
my tree now.
--
Sakari Ailus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-04-17 10:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-16 22:14 [PATCH] media: i2c: imx296: Fix error handling while reading temperature Christophe JAILLET
2023-04-17 5:30 ` Laurent Pinchart
2023-04-17 10:00 ` Sakari Ailus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®