mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: <Balakrishnan.S@microchip.com>
To: <ehristev@kernel.org>, <mchehab@kernel.org>
Cc: <hverkuil@kernel.org>, <sakari.ailus@linux.intel.com>,
	<linux-media@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<stable@vger.kernel.org>
Subject: Re: [PATCH v2 10/10] media: microchip-isc: fix WB offset and gain register field masking
Date: Mon, 20 Jul 2026 10:27:08 +0000	[thread overview]
Message-ID: <1bbde1e1-ccbf-4b59-b442-644d417c6c05@microchip.com> (raw)
In-Reply-To: <058e077d-acdb-4b86-8499-82b824759f08@kernel.org>

Hi Eugen,

On 17/07/26 10:59 am, Eugen Hristev wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> On 6/29/26 14:09, Balakrishnan Sambath wrote:
>> ISC_WB_O_* and ISC_WB_G_* pack two 13-bit fields per register. Sign
>> extension from negative offsets corrupts the upper field. Mask both
>> fields to 13 bits before packing.
>>
>> Fixes: 91b4e487b0c6 ("media: microchip: add ISC driver as Microchip ISC")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Balakrishnan Sambath <balakrishnan.s@microchip.com>
>> ---
>>   .../media/platform/microchip/microchip-isc-base.c  | 22 ++++++++++++++--------
>>   1 file changed, 14 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/drivers/media/platform/microchip/microchip-isc-base.c
>> index 1a9b97edfa32..79a58efb6333 100644
>> --- a/drivers/media/platform/microchip/microchip-isc-base.c
>> +++ b/drivers/media/platform/microchip/microchip-isc-base.c
>> @@ -62,18 +62,24 @@ static inline void isc_update_awb_ctrls(struct isc_device *isc)
>>
>>        /* In here we set our actual hw pipeline config */
>>
>> +     /*
>> +      * Offsets are 13-bit signed fields [12:0] and [28:16]. Cast to
>> +      * u32 and mask to 13 bits so sign extension of a negative value
>> +      * cannot corrupt the adjacent field.
>> +      */
>>        regmap_write(isc->regmap, ISC_WB_O_RGR,
>> -                  ((ctrls->offset[ISC_HIS_CFG_MODE_R])) |
>> -                  ((ctrls->offset[ISC_HIS_CFG_MODE_GR]) << 16));
>> +                  ((u32)ctrls->offset[ISC_HIS_CFG_MODE_R] & GENMASK(12, 0)) |
>> +                  (((u32)ctrls->offset[ISC_HIS_CFG_MODE_GR] & GENMASK(12, 0)) << 16));
>>        regmap_write(isc->regmap, ISC_WB_O_BGB,
>> -                  ((ctrls->offset[ISC_HIS_CFG_MODE_B])) |
>> -                  ((ctrls->offset[ISC_HIS_CFG_MODE_GB]) << 16));
>> +                  ((u32)ctrls->offset[ISC_HIS_CFG_MODE_B] & GENMASK(12, 0)) |
>> +                  (((u32)ctrls->offset[ISC_HIS_CFG_MODE_GB] & GENMASK(12, 0)) << 16));
>> +     /* Gains are 13-bit unsigned fields [12:0] and [28:16] */
>>        regmap_write(isc->regmap, ISC_WB_G_RGR,
>> -                  ctrls->gain[ISC_HIS_CFG_MODE_R] |
>> -                  (ctrls->gain[ISC_HIS_CFG_MODE_GR] << 16));
>> +                  (ctrls->gain[ISC_HIS_CFG_MODE_R] & GENMASK(12, 0)) |
>> +                  ((ctrls->gain[ISC_HIS_CFG_MODE_GR] & GENMASK(12, 0)) << 16));
>>        regmap_write(isc->regmap, ISC_WB_G_BGB,
>> -                  ctrls->gain[ISC_HIS_CFG_MODE_B] |
>> -                  (ctrls->gain[ISC_HIS_CFG_MODE_GB] << 16));
>> +                  (ctrls->gain[ISC_HIS_CFG_MODE_B] & GENMASK(12, 0)) |
>> +                  ((ctrls->gain[ISC_HIS_CFG_MODE_GB] & GENMASK(12, 0)) << 16));
>>   }
>>
> 
> Do you think you can rewrite these using FIELD_PREP ? It's getting a
> little complicated to understand what is being written here.

Makes sense, the WB offset/gain writes read much better that way.
Will rewrite them with FIELD_PREP in v3.

Thanks,
Balakrishnan

> 
> 
>>   static inline void isc_reset_awb_ctrls(struct isc_device *isc)
>>
> 


      reply	other threads:[~2026-07-20 10:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29 11:09 [PATCH v2 00/10] media: microchip-isc: AWB, stream-stop and endpoint-ref fixes Balakrishnan Sambath
2026-06-29 11:09 ` [PATCH v2 01/10] media: microchip-isc: fix awb_mutex and lock lifecycle Balakrishnan Sambath
2026-06-29 11:09 ` [PATCH v2 02/10] media: microchip-isc: take a reference on the parsed endpoints Balakrishnan Sambath
2026-06-29 11:09 ` [PATCH v2 03/10] media: microchip-isc: synchronize the IRQ before disabling clocks on stop Balakrishnan Sambath
2026-06-29 11:09 ` [PATCH v2 04/10] media: microchip-isc: disable histogram and flush AWB work on teardown Balakrishnan Sambath
2026-06-29 11:09 ` [PATCH v2 05/10] media: microchip-isc: do not touch WB registers when not streaming Balakrishnan Sambath
2026-06-29 11:09 ` [PATCH v2 06/10] media: microchip-isc: store the unshifted PFE_CFG0 BPS value Balakrishnan Sambath
2026-07-17  5:32   ` Eugen Hristev
2026-06-29 11:09 ` [PATCH v2 07/10] media: microchip-isc: fix ISC_PFG_CFG0_BPS macro name typo Balakrishnan Sambath
2026-07-17  5:31   ` Eugen Hristev
2026-06-29 11:09 ` [PATCH v2 08/10] media: microchip-isc: fix PM runtime leak in AWB work handler Balakrishnan Sambath
2026-06-29 11:09 ` [PATCH v2 09/10] media: microchip-isc: fix SBGGR10 Bayer pattern Balakrishnan Sambath
2026-06-29 11:09 ` [PATCH v2 10/10] media: microchip-isc: fix WB offset and gain register field masking Balakrishnan Sambath
2026-07-17  5:29   ` Eugen Hristev
2026-07-20 10:27     ` Balakrishnan.S [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1bbde1e1-ccbf-4b59-b442-644d417c6c05@microchip.com \
    --to=balakrishnan.s@microchip.com \
    --cc=ehristev@kernel.org \
    --cc=hverkuil@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome