From: Eugen Hristev <ehristev@kernel.org>
To: Balakrishnan Sambath <balakrishnan.s@microchip.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Hans Verkuil <hverkuil@kernel.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v3 10/10] media: microchip-isc: fix WB offset and gain register field masking
Date: Tue, 21 Jul 2026 16:19:36 +0300 [thread overview]
Message-ID: <a1720828-f0cc-41fb-9060-b8f937eaded2@kernel.org> (raw)
In-Reply-To: <20260721-balki-isc-prefix-fixes-v1-v3-10-ffe10640a2d9@microchip.com>
On 7/21/26 13:29, Balakrishnan Sambath wrote:
> ISC_WB_O_* and ISC_WB_G_* each pack two 13-bit fields. A negative offset
> sign-extends and corrupts the adjacent field. Add masks for the two
> fields and write them with FIELD_PREP(), which masks each value into its
> field, so sign extension can no longer bleed across.
>
> 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 | 21 +++++++++++++--------
> .../media/platform/microchip/microchip-isc-regs.h | 6 ++++++
> 2 files changed, 19 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..3d25d7d28652 100644
> --- a/drivers/media/platform/microchip/microchip-isc-base.c
> +++ b/drivers/media/platform/microchip/microchip-isc-base.c
> @@ -62,18 +62,23 @@ static inline void isc_update_awb_ctrls(struct isc_device *isc)
>
> /* In here we set our actual hw pipeline config */
>
> + /*
> + * Each register packs two 13-bit fields. FIELD_PREP() masks every
> + * value into its field, so sign extension of a negative offset can
> + * no longer bleed into the adjacent field.
> + */
I guess this comment does not make sense. It refers to a bad situation
in the past that is no longer valid. In time, it will be forgotten and
it does not make sense to mention it here.
At least my opinion on it.
> regmap_write(isc->regmap, ISC_WB_O_RGR,
> - ((ctrls->offset[ISC_HIS_CFG_MODE_R])) |
> - ((ctrls->offset[ISC_HIS_CFG_MODE_GR]) << 16));
> + FIELD_PREP(ISC_WB_O_LO, ctrls->offset[ISC_HIS_CFG_MODE_R]) |
> + FIELD_PREP(ISC_WB_O_HI, ctrls->offset[ISC_HIS_CFG_MODE_GR]));
> regmap_write(isc->regmap, ISC_WB_O_BGB,
> - ((ctrls->offset[ISC_HIS_CFG_MODE_B])) |
> - ((ctrls->offset[ISC_HIS_CFG_MODE_GB]) << 16));
> + FIELD_PREP(ISC_WB_O_LO, ctrls->offset[ISC_HIS_CFG_MODE_B]) |
> + FIELD_PREP(ISC_WB_O_HI, ctrls->offset[ISC_HIS_CFG_MODE_GB]));
> regmap_write(isc->regmap, ISC_WB_G_RGR,
> - ctrls->gain[ISC_HIS_CFG_MODE_R] |
> - (ctrls->gain[ISC_HIS_CFG_MODE_GR] << 16));
> + FIELD_PREP(ISC_WB_G_LO, ctrls->gain[ISC_HIS_CFG_MODE_R]) |
> + FIELD_PREP(ISC_WB_G_HI, ctrls->gain[ISC_HIS_CFG_MODE_GR]));
> regmap_write(isc->regmap, ISC_WB_G_BGB,
> - ctrls->gain[ISC_HIS_CFG_MODE_B] |
> - (ctrls->gain[ISC_HIS_CFG_MODE_GB] << 16));
> + FIELD_PREP(ISC_WB_G_LO, ctrls->gain[ISC_HIS_CFG_MODE_B]) |
> + FIELD_PREP(ISC_WB_G_HI, ctrls->gain[ISC_HIS_CFG_MODE_GB]));
> }
>
> static inline void isc_reset_awb_ctrls(struct isc_device *isc)
> diff --git a/drivers/media/platform/microchip/microchip-isc-regs.h b/drivers/media/platform/microchip/microchip-isc-regs.h
> index 9ddbbb6dd68b..fe145b142b82 100644
> --- a/drivers/media/platform/microchip/microchip-isc-regs.h
> +++ b/drivers/media/platform/microchip/microchip-isc-regs.h
> @@ -149,6 +149,12 @@
> /* ISC White Balance Gain for B, GB Register */
> #define ISC_WB_G_BGB 0x0000006c
>
> +/* Each WB offset/gain register packs two 13-bit fields, low and high */
> +#define ISC_WB_O_LO GENMASK(12, 0) /* R or B offset [12:0] */
> +#define ISC_WB_O_HI GENMASK(28, 16) /* GR or GB offset [28:16] */
> +#define ISC_WB_G_LO GENMASK(12, 0) /* R or B gain [12:0] */
> +#define ISC_WB_G_HI GENMASK(28, 16) /* GR or GB gain [28:16] */
> +
> /* ISC Color Filter Array Control Register */
> #define ISC_CFA_CTRL 0x00000070
>
>
next prev parent reply other threads:[~2026-07-21 13:19 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 10:28 [PATCH v3 00/10] media: microchip-isc: AWB, stream-stop and endpoint-ref fixes Balakrishnan Sambath
2026-07-21 10:28 ` [PATCH v3 01/10] media: microchip-isc: fix awb_mutex and lock lifecycle Balakrishnan Sambath
2026-07-21 13:27 ` Eugen Hristev
2026-07-23 9:36 ` Balakrishnan.S
2026-07-21 10:28 ` [PATCH v3 02/10] media: microchip-isc: take a reference on the parsed endpoints Balakrishnan Sambath
2026-07-21 10:28 ` [PATCH v3 03/10] media: microchip-isc: synchronize the IRQ before disabling clocks on stop Balakrishnan Sambath
2026-07-21 10:28 ` [PATCH v3 04/10] media: microchip-isc: disable histogram and flush AWB work on teardown Balakrishnan Sambath
2026-07-21 10:28 ` [PATCH v3 05/10] media: microchip-isc: do not touch WB registers when not streaming Balakrishnan Sambath
2026-07-21 10:29 ` [PATCH v3 06/10] media: microchip-isc: store the unshifted PFE_CFG0 BPS value Balakrishnan Sambath
2026-07-21 10:29 ` [PATCH v3 07/10] media: microchip-isc: fix ISC_PFG_CFG0_BPS macro name typo Balakrishnan Sambath
2026-07-21 10:29 ` [PATCH v3 08/10] media: microchip-isc: fix PM runtime leak in AWB work handler Balakrishnan Sambath
2026-07-21 10:29 ` [PATCH v3 09/10] media: microchip-isc: fix SBGGR10 Bayer pattern Balakrishnan Sambath
2026-07-21 10:29 ` [PATCH v3 10/10] media: microchip-isc: fix WB offset and gain register field masking Balakrishnan Sambath
2026-07-21 13:19 ` Eugen Hristev [this message]
2026-07-22 5:32 ` Balakrishnan.S
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=a1720828-f0cc-41fb-9060-b8f937eaded2@kernel.org \
--to=ehristev@kernel.org \
--cc=balakrishnan.s@microchip.com \
--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
all inboxes | Powered by JetHome®