Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ramesh Ramalingam" <r-ramalingam@ti.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v6 04/17] wifi: cc33xx: Add sdio.c, io.c, io.h
Date: Thu, 03 Dec 2026 07:33:48 +0000	[thread overview]
Message-ID: <sashiko-outbox-247294@kernel.org> (raw)
In-Reply-To: <20261203070906.1294171-5-r-ramalingam@ti.com>

Thank you for your contribution! Sashiko AI review found 17 potential
issues to consider:
- [High] wifi: cc33xx: uninitialized struct resource in
  sdio_cc33xx_probe()
- [High] wifi: cc33xx: use-after-free before IRQ teardown in
  sdio_cc33xx_remove()
- [High] wifi: cc33xx: deadlock and sleep-in-atomic in
  cc33xx_sdio_disable_irq()
- [Medium] wifi: cc33xx: use-after-free before free_irq() in
  sdio_cc33xx_probe()
- [Medium] wifi: cc33xx: runtime PM ref leak in cc33xx_sdio_power_on()
  on error
- [Medium] wifi: cc33xx: unbalanced pm_runtime_put_noidle() on probe
  failure
- [Medium] wifi: cc33xx: missing disable_irq_wake() on
  sdio_cc33xx_probe() error
- [Medium] wifi: cc33xx: cc33xx_suspend() returns -EINVAL when core
  driver unbound
- [Medium] wifi: cc33xx: cc33xx_probe_of() loses -EPROBE_DEFER from DT
  IRQ parse
- [Medium] wifi: cc33xx: unchecked sdio_f0_readb() in
  cc33xx_enable_async_interrupt()
- [Medium] wifi: cc33xx: ignored sdio_claim_irq() error in
  cc33xx_sdio_enable_irq()
- [Medium] wifi: cc33xx: cc33xx_sdio_set_block_size() ignores block-size
  error
- [Low] wifi: cc33xx: unprefixed global lock helpers and void* IRQ
  handler
- [Low] wifi: cc33xx: prohibited linux/gpio.h include and missing
  headers in sdio.c
- [Low] wifi: cc33xx: unused include of deprecated linux/gpio.h in
  sdio.c
- [Low] wifi: cc33xx: local SDIO IDs and early quirk mutation in
  sdio_cc33xx_probe()
- [Low] wifi: cc33xx: IRQ_NOAUTOEN flag leaked in sdio_cc33xx_probe()
--

commit a2cbcc4a1c662264be0a93163a1e9980d328c46f
Author: Michael Nemanov <michael.nemanov@ti.com>

wifi: cc33xx: Add sdio.c, io.c, io.h

This commit adds the SDIO transport driver and abstract I/O wrapper layer
for TI CC33xx wireless devices, supporting both out-of-band GPIO and
in-band SDIO interrupts.

> diff --git a/drivers/net/wireless/ti/cc33xx/io.h b/drivers/net/wireless/ti/cc33xx/io.h
> new file mode 100644
> index 0000000000000..35f6d4b483a6b
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/io.h

[ ... ]

> +void claim_core_status_lock(struct cc33xx *cc);
> +void release_core_status_lock(struct cc33xx *cc);

[Severity: Low]
Should claim_core_status_lock() and release_core_status_lock() carry the
cc33xx_ prefix used by the other helpers in io.h to avoid putting generic
names into the global symbol namespace when built into vmlinux?

Similarly, cc33xx_set_irq_handler() in sdio.c takes an untyped void *
handler and assigns it to pdev_data->irq_handler, bypassing compile-time
prototype checking instead of taking a typed function pointer.

> diff --git a/drivers/net/wireless/ti/cc33xx/sdio.c b/drivers/net/wireless/ti/cc33xx/sdio.c
> new file mode 100644
> index 0000000000000..5edbe1ebc7a80
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/sdio.c
> @@ -0,0 +1,515 @@

[ ... ]

> +#include <linux/gpio.h>

[Severity: Low]
This file does not call any GPIO APIs, and include/linux/gpio.h is
deprecated with a notice that it must not be included by new code.  Can
this include be dropped?

> +#include <linux/pm_runtime.h>
> +#include <linux/of_irq.h>
> +
> +#include "cc33xx.h"
> +#include "io.h"

[Severity: Low]
In addition to the prohibited linux/gpio.h include, sdio.c includes io.h
without using any declaration from it, while relying on transitive includes
for linux/module.h, linux/mmc/card.h, linux/interrupt.h, linux/irq.h, and
linux/of.h.  Adding direct includes for the APIs used here will keep this
file resilient to header cleanups.

> +
> +#ifndef SDIO_VENDOR_ID_TI
> +#define SDIO_VENDOR_ID_TI		0x0097
> +#endif
> +
> +#define SDIO_DEVICE_ID_CC33XX_NO_EFUSE	0x4076
> +#define SDIO_DEVICE_ID_TI_CC33XX	0x4077

[Severity: Low]
Should these IDs use linux/mmc/sdio_ids.h instead of local definitions?
sdio_ids.h already defines SDIO_VENDOR_ID_TI and 0x4076 as
SDIO_DEVICE_ID_TI_WL1271, so exporting 0x0097:0x4076 in cc33xx_devices[]
collides with wlcore_sdio's modalias and causes both modules to autoload on
0x0097:0x4076 hardware.

In addition, sdio_cc33xx_probe() sets MMC_QUIRK_LENIENT_FN0 and
MMC_QUIRK_BLKSZ_FOR_BYTE_MODE on the shared func->card->quirks before
cc33xx_probe_of() confirms the device matches ti,cc3300, mutating card
state even when rejecting a non-CC33xx card with -ENODEV.

[ ... ]

> +static void cc33xx_sdio_set_block_size(struct device *child,
> +				       unsigned int blksz)
> +{
> +	struct cc33xx_sdio_glue *glue = dev_get_drvdata(child->parent);
> +	struct sdio_func *func = dev_to_sdio_func(glue->dev);
> +
> +	sdio_claim_host(func);
> +	sdio_set_block_size(func, blksz);
> +	sdio_release_host(func);
> +}

[Severity: Medium]
Why is the return value of sdio_set_block_size() discarded here?

When sdio_set_block_size() fails (for example with -EINVAL or an FBR write
error), func->cur_blksize is left unchanged, yet cc33xx_set_block_size() in
io.c unconditionally returns true.  cc33xx_chip_wakeup() relies on a false
return to clear CC33XX_QUIRK_TX_BLOCKSIZE_ALIGN, so subsequent transfers
would use a mismatched block size.

[ ... ]

> +static int cc33xx_sdio_power_on(struct cc33xx_sdio_glue *glue)
> +{
> +	int ret;
> +	struct sdio_func *func = dev_to_sdio_func(glue->dev);
> +	struct mmc_card *card = func->card;
> +
> +	ret = pm_runtime_get_sync(&card->dev);
> +	if (ret < 0) {
> +		pm_runtime_put_noidle(&card->dev);
> +		dev_err(glue->dev, "%s: failed to get_sync(%d)\n",
> +			__func__, ret);
> +
> +		return ret;
> +	}
> +
> +	sdio_claim_host(func);
> +	ret = sdio_enable_func(func);
> +	sdio_release_host(func);
> +
> +	return ret;
> +}

[Severity: Medium]
Does this leak a runtime PM reference on card->dev when sdio_enable_func()
fails?

If sdio_enable_func() returns an error, cc33xx_power_on() leaves
CC33XX_FLAG_GPIO_POWER clear, so cc33xx_power_off() will not call
cc33xx_sdio_power_off() to drop the reference taken by
pm_runtime_get_sync().  Calling pm_runtime_put(&card->dev) on error (and
using pm_runtime_resume_and_get()) would keep the count balanced.

[ ... ]

> +static void cc33xx_enable_async_interrupt(struct sdio_func *func)
> +{
> +	u8 reg_val;
> +	const int CCCR_REG_16_ADDR = 0x16;
> +	const int ENABLE_ASYNC_IRQ_BIT = BIT(1);
> +
> +	reg_val = sdio_f0_readb(func, CCCR_REG_16_ADDR, NULL);
> +	reg_val |= ENABLE_ASYNC_IRQ_BIT;
> +	sdio_f0_writeb(func, reg_val, CCCR_REG_16_ADDR, NULL);
> +}

[Severity: Medium]
Can ignoring the error from sdio_f0_readb() corrupt CCCR register 0x16?

sdio_f0_readb() returns 0xFF on a transfer error, so without checking
err_ret a transient CMD52 read failure causes sdio_f0_writeb() to write
0xFF back to SDIO_CCCR_INTERRUPT_EXT and clobber reserved bits.  This also
sets EAI without checking SDIO_INTERRUPT_EXT_SAI or updating
func->card->cccr.enable_async_irq, and duplicates SDIO_CCCR_INTERRUPT_EXT
and SDIO_INTERRUPT_EXT_EAI from linux/mmc/sdio.h.

> +
> +static void cc33xx_sdio_enable_irq(struct device *child)
> +{
> +	struct cc33xx_sdio_glue *glue = dev_get_drvdata(child->parent);
> +	struct sdio_func *func = dev_to_sdio_func(glue->dev);
> +
> +	sdio_claim_host(func);
> +	cc33xx_enable_async_interrupt(func);
> +	sdio_claim_irq(func, inband_irq_handler);
> +	sdio_release_host(func);
> +}

[Severity: Medium]
Does discarding the return value of sdio_claim_irq() hide in-band IRQ
registration failures?

If sdio_claim_irq() fails (for example with -EBUSY or an SDIO I/O error),
func->irq_handler stays NULL and the driver silently receives no in-band
interrupts until later boot or command timeouts.

> +
> +static void cc33xx_sdio_disable_irq(struct device *child)
> +{
> +	struct cc33xx_sdio_glue *glue = dev_get_drvdata(child->parent);
> +	struct sdio_func *func = dev_to_sdio_func(glue->dev);
> +
> +	sdio_claim_host(func);
> +	sdio_release_irq(func);
> +	sdio_release_host(func);
> +}

[Severity: High]
Can cc33xx_sdio_disable_irq() sleep in atomic context and self-deadlock
when invoked through cc33xx_disable_interrupts_nosync()?

Unlike disable_irq_nosync() in the GPIO IRQ path, cc33xx_sdio_disable_irq()
calls sleeping sdio_claim_host() and sdio_release_irq(), which calls
kthread_stop(host->sdio_irq_thread).  When an in-band SDIO IRQ arrives
while CC33XX_FLAG_SUSPENDED is set, the IRQ thread calls back into
cc33xx_sdio_disable_irq() under cc->cc_lock:

sdio_irq_thread
  inband_irq_handler()
    ... -> cc33xx_irq()
      spin_lock_irqsave(&cc->cc_lock)
      cc33xx_disable_interrupts_nosync()
        cc33xx_sdio_disable_irq()
          sdio_claim_host()            <-- sleep in atomic context
          sdio_release_irq()
            kthread_stop(current)      <-- self-deadlock

In addition, sdio_claim_irq() and sdio_release_irq() do not provide the
nested disable-depth semantics of enable_irq() and disable_irq_nosync().

[ ... ]

> +static int cc33xx_probe_of(struct device *dev, int *irq, int *wakeirq,
> +			   struct cc33xx_platdev_data *pdev_data)
> +{
> +	struct device_node *np = dev->of_node;
> +	const struct of_device_id *of_id;
> +
> +	of_id = of_match_node(cc33xx_sdio_of_match_table, np);
> +	if (!of_id)
> +		return -ENODEV;
> +
> +	pdev_data->family = of_id->data;
> +
> +	*irq = irq_of_parse_and_map(np, 0);
> +
> +	*wakeirq = irq_of_parse_and_map(np, 1);
> +
> +	return 0;
> +}

[Severity: Medium]
Does irq_of_parse_and_map() lose -EPROBE_DEFER when the GPIO interrupt
controller has not probed yet?

irq_of_parse_and_map() returns 0 both when the interrupts property is
omitted and when the IRQ domain is not yet registered, so
sdio_cc33xx_probe() silently falls back to sdio_ops_inband_irq instead of
deferring probe.  Using of_irq_get() distinguishes -EPROBE_DEFER from an
absent interrupts property.

[ ... ]

> +	/* Tell PM core that we don't need the card to be powered now */
> +	pm_runtime_put_noidle(&func->dev);
> +
> +	glue->core = platform_device_alloc("cc33xx", PLATFORM_DEVID_AUTO);
> +	if (!glue->core) {
> +		dev_err(glue->dev, "can't allocate platform_device\n");
> +		return -ENOMEM;
> +	}

[Severity: Medium]
Is pm_runtime_put_noidle(&func->dev) unbalanced on probe failure?

sdio_bus_probe() already calls pm_runtime_put_noidle(&func->dev) when
drv->probe() returns an error, and neither the -ENOMEM return above nor
out_dev_put restores the reference with pm_runtime_get_noresume(&func->dev).
Any failure after this point results in a double put on func->dev.

[ ... ]

> +		irq_set_status_flags(gpio_irq, IRQ_NOAUTOEN);
> +
> +		if (irq_flags & (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW))
> +			irq_flags |= IRQF_ONESHOT;
> +
> +		ret = request_threaded_irq(gpio_irq, gpio_irq_hard_handler,
> +					   gpio_irq_thread_handler,
> +					   irq_flags, glue->core->name, func);

[Severity: Low]
Does calling irq_set_status_flags(gpio_irq, IRQ_NOAUTOEN) leak the
IRQ_NOAUTOEN flag on the persistent irq_desc?

Neither probe error unwind nor sdio_cc33xx_remove() clears IRQ_NOAUTOEN, so
a later consumer of that GPIO IRQ without IRQF_NO_AUTOEN would find its
interrupt left disabled.  Passing IRQF_NO_AUTOEN in irq_flags to
request_threaded_irq() avoids mutating desc->status_use_accessors before
acquiring the IRQ.

[ ... ]

> +		if ((mmcflags & MMC_PM_KEEP_POWER) &&
> +		    (enable_irq_wake(gpio_irq) == 0))
> +			pdev_data->pwr_in_suspend = true;

[Severity: Medium]
Does the out_dev_put error path leak the IRQ wake reference enabled here?

free_irq() does not decrement desc->wake_depth, so if a subsequent step
such as platform_device_add() fails, out_dev_put needs to call
disable_irq_wake(pdev_data->gpio_irq_num) when pdev_data->pwr_in_suspend is
true.

[ ... ]

> +	if (wakeirq > 0) {
> +		res[0].start = wakeirq;
> +		res[0].flags = IORESOURCE_IRQ |
> +			irqd_get_trigger_type(irq_get_irq_data(wakeirq));
> +		res[0].name = "wakeirq";
> +
> +		ret = platform_device_add_resources(glue->core, res, 1);

[Severity: High]
Can uninitialized fields in res[0] crash platform_device_add()?

res[1] is declared on the stack without initialization and only start,
flags, and name are written, leaving end, parent, sibling, child, and desc
holding stack garbage.  platform_device_add() copies res[0] and passes any
non-NULL r->parent directly to insert_resource(), dereferencing stack
garbage during probe whenever wakeirq is configured.  Initializing res[0]
with DEFINE_RES_IRQ_NAMED(wakeirq, "wakeirq") (or zero-initializing res and
setting res[0].end = wakeirq) fixes this.

[ ... ]

> +out_dev_put:
> +	platform_device_put(glue->core);
> +
> +	if (pdev_data->gpio_irq_num)
> +		free_irq(pdev_data->gpio_irq_num, func);
> +
> +	return ret;

[Severity: Medium]
Can freeing glue->core before free_irq() cause a use-after-free of
action->name?

request_threaded_irq() stores glue->core->name directly in action->name
without copying it, so platform_device_put(glue->core) frees that string
while the irqaction is still visible to /proc/interrupts readers.  Calling
free_irq() before platform_device_put(glue->core) closes that window.

> +static void sdio_cc33xx_remove(struct sdio_func *func)
> +{
> +	struct cc33xx_sdio_glue *glue = sdio_get_drvdata(func);
> +	struct platform_device *pdev = glue->core;
> +	struct cc33xx_platdev_data *pdev_data = dev_get_platdata(&pdev->dev);
> +
> +	int gpio_irq_num = pdev_data->gpio_irq_num;
> +	bool pwr_in_suspend = pdev_data->pwr_in_suspend;
> +
> +	/* Undo decrement done above in sdio_cc33xx_probe */
> +	pm_runtime_get_noresume(&func->dev);
> +
> +	/* Do not use pdev_data after this point */
> +	platform_device_unregister(glue->core);
> +
> +	if (gpio_irq_num) {
> +		free_irq(gpio_irq_num, func);
> +		if (pwr_in_suspend)
> +			disable_irq_wake(gpio_irq_num);
> +	} else {
> +		sdio_claim_host(func);
> +		sdio_release_irq(func);
> +		sdio_release_host(func);
> +	}
> +}

[Severity: High]
Can an in-flight IRQ handler dereference freed glue->core and pdev_data
between platform_device_unregister() and free_irq() / sdio_release_irq()?

platform_device_unregister() drops the final reference and frees
glue->core, glue->core->name, and pdev_data before free_irq() or
sdio_release_irq() synchronizes and removes the IRQ handlers:

CPU0                                  CPU1
sdio_cc33xx_remove()
  platform_device_unregister(...)
    platform_device_release()
      kfree(pdev_data)
      kfree(glue->core)
                                      gpio_irq_thread_handler()
                                        dev_get_platdata(&pdev->dev)
                                        pdev_data->irq_handler(pdev)
                                          <-- use-after-free
  free_irq(gpio_irq_num, func)

The same window also leaves action->name pointing to freed glue->core->name
for /proc/interrupts readers.  Calling platform_device_del(glue->core),
then tearing down the IRQ, and finally calling
platform_device_put(glue->core) avoids both use-after-free paths.

[ ... ]

> +	if (!cc) {
> +		dev_err(dev, "no cc33xx module was probed\n");
> +		return -EINVAL;
> +	}

[Severity: Medium]
Should cc33xx_suspend() return 0 rather than -EINVAL when the child cc33xx
platform driver is not bound?

Returning -EINVAL aborts system-wide suspend whenever the separate cc33xx
module is not loaded or was unbound, even though the card can safely be
powered down (wlcore/sdio.c returns 0 in this case).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=4

  reply	other threads:[~2026-12-03  7:33 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  7:08 [PATCH v6 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family Ramesh Ramalingam
2026-12-03  7:08 ` [PATCH v6 01/17] dt-bindings: net: wireless: cc33xx: Add ti,cc33xx.yaml Ramesh Ramalingam
2026-12-03  7:20   ` sashiko-bot
2026-12-03  7:08 ` [PATCH v6 02/17] wifi: cc33xx: Add cc33xx.h, cc33xx_i.h Ramesh Ramalingam
2026-12-03  7:31   ` sashiko-bot
2026-12-03  7:08 ` [PATCH v6 03/17] wifi: cc33xx: Add debug.h Ramesh Ramalingam
2026-12-03  7:26   ` sashiko-bot
2026-12-03  7:08 ` [PATCH v6 04/17] wifi: cc33xx: Add sdio.c, io.c, io.h Ramesh Ramalingam
2026-12-03  7:33   ` sashiko-bot [this message]
2026-12-03  7:08 ` [PATCH v6 05/17] wifi: cc33xx: Add cmd.c, cmd.h Ramesh Ramalingam
2026-12-03  7:42   ` sashiko-bot
2026-12-03  7:08 ` [PATCH v6 06/17] wifi: cc33xx: Add acx.c, acx.h Ramesh Ramalingam
2026-12-03  7:32   ` sashiko-bot
2026-12-03  7:08 ` [PATCH v6 07/17] wifi: cc33xx: Add event.c, event.h Ramesh Ramalingam
2026-12-03  7:31   ` sashiko-bot
2026-12-03  7:08 ` [PATCH v6 08/17] wifi: cc33xx: Add boot.c, boot.h Ramesh Ramalingam
2026-12-03  7:38   ` sashiko-bot
2026-12-03  7:08 ` [PATCH v6 09/17] wifi: cc33xx: Add main.c Ramesh Ramalingam
2026-12-03  7:08 ` [PATCH v6 10/17] wifi: cc33xx: Add rx.c, rx.h Ramesh Ramalingam
2026-12-03  7:33   ` sashiko-bot
2026-12-03  7:09 ` [PATCH v6 11/17] wifi: cc33xx: Add tx.c, tx.h Ramesh Ramalingam
2026-12-03  7:47   ` sashiko-bot
2026-12-03  7:09 ` [PATCH v6 12/17] wifi: cc33xx: Add init.c, init.h Ramesh Ramalingam
2026-12-03  7:43   ` sashiko-bot
2026-12-03  7:09 ` [PATCH v6 13/17] wifi: cc33xx: Add scan.c, scan.h Ramesh Ramalingam
2026-12-03  7:52   ` sashiko-bot
2026-12-03  7:09 ` [PATCH v6 14/17] wifi: cc33xx: Add conf.h Ramesh Ramalingam
2026-12-03  7:50   ` sashiko-bot
2026-12-03  7:09 ` [PATCH v6 15/17] wifi: cc33xx: Add ps.c, ps.h Ramesh Ramalingam
2026-12-03  7:43   ` sashiko-bot
2026-12-03  7:09 ` [PATCH v6 16/17] wifi: cc33xx: Add testmode.c, testmode.h Ramesh Ramalingam
2026-12-03  7:48   ` sashiko-bot
2026-12-03  7:09 ` [PATCH v6 17/17] wifi: cc33xx: Add Kconfig, Makefile Ramesh Ramalingam
2026-12-03  7:46   ` 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=sashiko-outbox-247294@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=r-ramalingam@ti.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox