All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Svyatoslav Ryhel" <clamor95@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 4/6] mfd: lm3533: Set DMA mask
Date: Thu, 28 May 2026 15:28:49 +0000	[thread overview]
Message-ID: <20260528152850.2953C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260528135123.103745-5-clamor95@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The `lm3533_cells` array is allocated on the stack without being zero-initialized, and an unconditional `count++` leads to uninitialized elements being passed to the MFD core, risking memory corruption or kernel panics.
- [Medium] An off-by-one error in the validation of the backlight `reg` property allows it to overlap with the LED `reg` address space.
--

commit e3db8e2c46ac0e3ca30554a0b5ae2956e28c6227
Author: Svyatoslav Ryhel <clamor95@gmail.com>

mfd: lm3533: Set DMA mask

Missing coherent_dma_mask assigning triggers a warning in dmesg. This sets
coherent_dma_mask to zero because both the core and cells do not utilize
dma.

> diff --git a/drivers/mfd/lm3533-core.c b/drivers/mfd/lm3533-core.c
> index 519f8c16a3f35..3cfdebf5fb52b 100644
> --- a/drivers/mfd/lm3533-core.c
> +++ b/drivers/mfd/lm3533-core.c
> @@ -526,6 +526,10 @@ static int lm3533_i2c_probe(struct i2c_client *i2c)
>  				   LM3533_BOOST_FREQ_MAX);
>  	lm3533->boost_freq = lm3533->boost_freq / (500 * KILO) - 1;
>  
> +	/* LM3533 and child devices do not use DMA */
> +	i2c->dev.coherent_dma_mask = 0;
> +	i2c->dev.dma_mask = &i2c->dev.coherent_dma_mask;
> +
>  	return lm3533_device_init(lm3533);

[Severity: High]
Does this call to lm3533_device_init() pass uninitialized elements to the mfd
core?  Looking at lm3533_device_init(), the lm3533_cells array is allocated
on the stack without zero-initialization.

If a child node is present in the device tree that does not match any of the
recognized compatible strings, the iteration loop skips the initialization
blocks but still unconditionally executes count++, leaving the array element
with stack garbage:

drivers/mfd/lm3533-core.c:lm3533_device_init() {
    struct mfd_cell lm3533_cells[LM3533_CELLS_MAX];
    u32 count = 0, reg;
    ...
    device_for_each_child_node_scoped(lm3533->dev, child) {
        if (!fwnode_device_is_available(child))
            continue;

        if (count >= LM3533_CELLS_MAX)
            break;

        if (fwnode_device_is_compatible(child, "ti,lm3533-als")) {
            ...
        }
        if (fwnode_device_is_compatible(child, "ti,lm3533-backlight")) {
            ...
        }
        if (fwnode_device_is_compatible(child, "ti,lm3533-leds")) {
            ...
        }

        count++;
    }
    ...
    ret = mfd_add_devices(dev, 0, lm3533_cells, count, NULL, 0, NULL);
}

When this array is passed to mfd_add_devices(), the mfd core will attempt to
dereference a garbage pointer for the device name.  Can this cause memory
corruption or a kernel panic?


[Severity: Medium]
Can an invalid backlight reg value overlap with the LED reg address space?
Looking at lm3533_device_init(), the validation allows reg = 2 to be accepted
for a backlight:

drivers/mfd/lm3533-core.c:lm3533_device_init() {
        ...
        if (fwnode_device_is_compatible(child, "ti,lm3533-backlight")) {
            ret = fwnode_property_read_u32(child, "reg", &reg);
            if (ret || reg > LM3533_HVLED_ID_MAX) {
                dev_err(dev, "invalid backlight reg %d\n", reg);
                continue;
            }
        ...
}

LM3533_HVLED_ID_MAX is 2.  This incorrectly allows reg = 2 to be accepted for
a backlight, assigning it an ID of 2, even though the backlight driver only
supports 2 control banks (IDs 0 and 1).

While the backlight child driver safely returns -EINVAL during probe when it
encounters ID 2, should this check be reg >= LM3533_HVLED_ID_MAX to reject
invalid device tree configurations early in the core driver?

>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260528135123.103745-1-clamor95@gmail.com?part=4

  reply	other threads:[~2026-05-28 15:28 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-28 13:51 [PATCH v2 0/6] mfd: lm3533: convert to OF bindings, improve support Svyatoslav Ryhel
2026-05-28 13:51 ` [PATCH v2 1/6] dt-bindings: leds: Document TI LM3533 LED controller Svyatoslav Ryhel
2026-05-28 14:08   ` sashiko-bot
2026-05-28 14:54   ` Jonathan Cameron
2026-05-29  9:51   ` Daniel Thompson
2026-05-29 10:07     ` Svyatoslav Ryhel
2026-05-29 10:46       ` Daniel Thompson
2026-05-29 10:56         ` Svyatoslav Ryhel
2026-05-28 13:51 ` [PATCH v2 2/6] mfd: lm3533: Convert to use OF bindings Svyatoslav Ryhel
2026-05-28 14:37   ` sashiko-bot
2026-05-28 14:50   ` Jonathan Cameron
2026-05-28 15:03     ` Svyatoslav Ryhel
2026-05-29  9:08       ` Jonathan Cameron
2026-05-29  9:39         ` Svyatoslav Ryhel
2026-05-29 10:48           ` Jonathan Cameron
2026-05-29 11:02             ` Svyatoslav Ryhel
2026-05-29 13:10               ` Jonathan Cameron
2026-05-29 11:00   ` Daniel Thompson
2026-05-29 11:06     ` Svyatoslav Ryhel
2026-05-28 13:51 ` [PATCH v2 3/6] mfd: lm3533: Add support for VIN power supply Svyatoslav Ryhel
2026-05-28 14:56   ` sashiko-bot
2026-05-28 13:51 ` [PATCH v2 4/6] mfd: lm3533: Set DMA mask Svyatoslav Ryhel
2026-05-28 15:28   ` sashiko-bot [this message]
2026-05-28 13:51 ` [PATCH v2 5/6] video: backlight: lm3533_bl: Set initial mapping mode from DT Svyatoslav Ryhel
2026-05-28 16:00   ` sashiko-bot
2026-05-29 11:10   ` Daniel Thompson
2026-05-29 11:17     ` Svyatoslav Ryhel
2026-05-29 11:40       ` Daniel Thompson
2026-05-28 13:51 ` [PATCH v2 6/6] video: leds: backlight: lm3533: Support getting LED sources " Svyatoslav Ryhel
2026-05-28 16:33   ` sashiko-bot

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=20260528152850.2953C1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=clamor95@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.