Skip to contentSkip to conversation

mfd: nct6694: Refactor transport layer and add HIF (eSPI) support

PATCH Superseded [email protected] 4 participants 5 messages May 15 – May 16

Subsystems (11)
Networking Network drivers USB GPIO +7 more subsystems

v4 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v4 cover mfd: nct6694: Refactor transport layer and add HIF (eSPI) support

From: Ming Yu <[email protected]>

The Nuvoton NCT6694 is a peripheral expander that provides GPIO, I2C, CAN-FD, Watchdog, HWMON, PWM, and RTC sub-devices. Currently, the driver only supports USB as the host transport interface.

This series refactors the NCT6694 MFD core to support multiple transport backends and adds a new Host Interface (HIF) transport driver that communicates over eSPI using Super-I/O shared memory.

Changes since version 3:
- Remove redundant module type macro definitions from sub-device drivers that are now provided by the shared header <linux/mfd/nct6694.h>, fixing -Wmacro-redefined warnings.

Changes since version 2:
- Restore per-device IDA and mfd_add_hotplug_devices()/PLATFORM_DEVID_AUTO to avoid child device ID conflicts with multiple NCT6694 chips.
- Validate irq_find_mapping() return value before dispatching IRQs.
- Check superio_enter() return value in nct6694_irq_init().

Changes since version 1:
- Reworked the Super-I/O access helpers.

Ming Yu (1):
mfd: Add Host Interface (HIF) support for Nuvoton NCT6694

 MAINTAINERS                         |   1 +
 drivers/gpio/gpio-nct6694.c         |   7 -
 drivers/hwmon/nct6694-hwmon.c       |  21 -
 drivers/i2c/busses/i2c-nct6694.c    |   7 -
 drivers/mfd/Kconfig                 |  47 +-
 drivers/mfd/Makefile                |   3 +-
 drivers/mfd/nct6694-hif.c           | 663 ++++++++++++++++++++++++++++
 drivers/mfd/nct6694.c               | 111 +++--
 drivers/net/can/usb/nct6694_canfd.c |   6 -
 drivers/rtc/rtc-nct6694.c           |   7 -
 drivers/watchdog/nct6694_wdt.c      |   7 -
 include/linux/mfd/nct6694.h         |  54 ++-
 12 files changed, 813 insertions(+), 121 deletions(-)
 create mode 100644 drivers/mfd/nct6694-hif.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/1 mfd: Add Host Interface (HIF) support for Nuvoton NCT6694

From: Ming Yu <[email protected]>

The Nuvoton NCT6694 also provides a Host Interface (HIF) via eSPI to the host to access its features.

Sub-devices can use the common functions nct6694_read_msg() and nct6694_write_msg() to issue a command. They can also request interrupts that will be called when the HIF device triggers a shared memory interrupt.

To support multiple transports, the driver configuration is updated to allow selecting between the USB and HIF interfaces.

---
Changes since version 3:
- Remove redundant module type macro definitions from sub-device drivers that are now provided by the shared header <linux/mfd/nct6694.h>, fixing -Wmacro-redefined warnings.

Changes since version 2:
- Restore per-device IDA and mfd_add_hotplug_devices()/PLATFORM_DEVID_AUTO to avoid child device ID conflicts with multiple NCT6694 chips.
- Validate irq_find_mapping() return value before dispatching IRQs.
- Check superio_enter() return value in nct6694_irq_init().

Changes since version 1:
- Drop function pointers from Super-I/O access and use static inline helpers with proper types.

 MAINTAINERS                         |   1 +
 drivers/gpio/gpio-nct6694.c         |   7 -
 drivers/hwmon/nct6694-hwmon.c       |  21 -
 drivers/i2c/busses/i2c-nct6694.c    |   7 -
 drivers/mfd/Kconfig                 |  47 +-
 drivers/mfd/Makefile                |   3 +-
 drivers/mfd/nct6694-hif.c           | 663 ++++++++++++++++++++++++++++
 drivers/mfd/nct6694.c               | 111 +++--
 drivers/net/can/usb/nct6694_canfd.c |   6 -
 drivers/rtc/rtc-nct6694.c           |   7 -
 drivers/watchdog/nct6694_wdt.c      |   7 -
 include/linux/mfd/nct6694.h         |  54 ++-
 12 files changed, 813 insertions(+), 121 deletions(-)
 create mode 100644 drivers/mfd/nct6694-hif.c
MAINTAINERS +1 -0
index 6aa3fe2ee1bb..e39aad82132e 100644
@@ -19091,6 +19091,7 @@ S:	Supported
 F:	drivers/gpio/gpio-nct6694.c
 F:	drivers/hwmon/nct6694-hwmon.c
 F:	drivers/i2c/busses/i2c-nct6694.c
+F:	drivers/mfd/nct6694-hif.c
 F:	drivers/mfd/nct6694.c
 F:	drivers/net/can/usb/nct6694_canfd.c
 F:	drivers/rtc/rtc-nct6694.c
drivers/gpio/gpio-nct6694.c +0 -7
index a8607f0d9915..53bfc5983648 100644
@@ -13,13 +13,6 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 
-/*
- * USB command module type for NCT6694 GPIO controller.
- * This defines the module type used for communication with the NCT6694
- * GPIO controller over the USB interface.
- */
-#define NCT6694_GPIO_MOD	0xFF
-
 #define NCT6694_GPIO_VER	0x90
 #define NCT6694_GPIO_VALID	0x110
 #define NCT6694_GPI_DATA	0x120
drivers/hwmon/nct6694-hwmon.c +0 -21
index 6dcf22ca5018..581451875f2c 100644
@@ -15,13 +15,6 @@
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 
-/*
- * USB command module type for NCT6694 report channel
- * This defines the module type used for communication with the NCT6694
- * report channel over the USB interface.
- */
-#define NCT6694_RPT_MOD			0xFF
-
 /* Report channel */
 /*
  * The report channel is used to report the status of the hardware monitor
@@ -38,13 +31,6 @@
 #define NCT6694_TIN_STS(x)		(0x6A + (x))
 #define NCT6694_FIN_STS(x)		(0x6E + (x))
 
-/*
- * USB command module type for NCT6694 HWMON controller.
- * This defines the module type used for communication with the NCT6694
- * HWMON controller over the USB interface.
- */
-#define NCT6694_HWMON_MOD		0x00
-
 /* Command 00h - Hardware Monitor Control */
 #define NCT6694_HWMON_CONTROL		0x00
 #define NCT6694_HWMON_CONTROL_SEL	0x00
@@ -53,13 +39,6 @@
 #define NCT6694_HWMON_ALARM		0x02
 #define NCT6694_HWMON_ALARM_SEL		0x00
 
-/*
- * USB command module type for NCT6694 PWM controller.
- * This defines the module type used for communication with the NCT6694
- * PWM controller over the USB interface.
- */
-#define NCT6694_PWM_MOD			0x01
-
 /* PWM Command - Manual Control */
 #define NCT6694_PWM_CONTROL		0x01
 #define NCT6694_PWM_CONTROL_SEL		0x00
drivers/i2c/busses/i2c-nct6694.c +0 -7
index 1413ab6f9462..ef3329f34246 100644
@@ -12,13 +12,6 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 
-/*
- * USB command module type for NCT6694 I2C controller.
- * This defines the module type used for communication with the NCT6694
- * I2C controller over the USB interface.
- */
-#define NCT6694_I2C_MOD			0x03
-
 /* Command 00h - I2C Deliver */
 #define NCT6694_I2C_DELIVER		0x00
 #define NCT6694_I2C_DELIVER_SEL		0x00
drivers/mfd/Kconfig +37 -10

56 lines not on this page · raw message

drivers/mfd/Makefile +2 -1
index e75e8045c28a..4cee9b74978c 100644
@@ -124,7 +124,8 @@ obj-$(CONFIG_MFD_MC13XXX_I2C)	+= mc13xxx-i2c.o
 
 obj-$(CONFIG_MFD_PF1550)	+= pf1550.o
 
-obj-$(CONFIG_MFD_NCT6694)	+= nct6694.o
+obj-$(CONFIG_MFD_NCT6694_HIF)	+= nct6694-hif.o
+obj-$(CONFIG_MFD_NCT6694_USB)	+= nct6694.o
 
 obj-$(CONFIG_MFD_CORE)		+= mfd-core.o
 
drivers/mfd/nct6694-hif.c new file +663 -0

663 lines not on this page · raw message

drivers/mfd/nct6694.c +75 -36

240 lines not on this page · raw message

drivers/net/can/usb/nct6694_canfd.c +0 -6
index e5f7f8849a73..262b4c26c9d4 100644
@@ -18,12 +18,6 @@
 
 #define DEVICE_NAME "nct6694-canfd"
 
-/* USB command module type for NCT6694 CANfd controller.
- * This defines the module type used for communication with the NCT6694
- * CANfd controller over the USB interface.
- */
-#define NCT6694_CANFD_MOD			0x05
-
 /* Command 00h - CAN Setting and Initialization */
 #define NCT6694_CANFD_SETTING			0x00
 #define NCT6694_CANFD_SETTING_ACTIVE_CTRL1	BIT(0)
drivers/rtc/rtc-nct6694.c +0 -7
index 35401a0d9cf5..c06902f150c9 100644
@@ -14,13 +14,6 @@
 #include <linux/rtc.h>
 #include <linux/slab.h>
 
-/*
- * USB command module type for NCT6694 RTC controller.
- * This defines the module type used for communication with the NCT6694
- * RTC controller over the USB interface.
- */
-#define NCT6694_RTC_MOD		0x08
-
 /* Command 00h - RTC Time */
 #define NCT6694_RTC_TIME	0x0000
 #define NCT6694_RTC_TIME_SEL	0x00
drivers/watchdog/nct6694_wdt.c +0 -7
index bc3689bd4b6b..4c06ac105562 100644
@@ -20,13 +20,6 @@
 
 #define NCT6694_WDT_MAX_DEVS		2
 
-/*
- * USB command module type for NCT6694 WDT controller.
- * This defines the module type used for communication with the NCT6694
- * WDT controller over the USB interface.
- */
-#define NCT6694_WDT_MOD			0x07
-
 /* Command 00h - WDT Setup */
 #define NCT6694_WDT_SETUP		0x00
 #define NCT6694_WDT_SETUP_SEL(idx)	(idx ? 0x01 : 0x00)
include/linux/mfd/nct6694.h +35 -19

84 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v4 1/1] mfd: Add Host Interface (HIF) support for Nuvoton NCT6694

Quoted 9 lines
 MAINTAINERS                         |   1 +
 drivers/gpio/gpio-nct6694.c         |   7 -
 drivers/hwmon/nct6694-hwmon.c       |  21 -
 drivers/i2c/busses/i2c-nct6694.c    |   7 -
 drivers/mfd/Kconfig                 |  47 +-
 drivers/mfd/Makefile                |   3 +-
 drivers/mfd/nct6694-hif.c           | 663 ++++++++++++++++++++++++++++
 drivers/mfd/nct6694.c               | 111 +++--
 drivers/net/can/usb/nct6694_canfd.c |   6 -

The networking change here is very small, so my influence as a networking Maintainer should be considered small.

However, i would say this patch is too big, does too many different things at once, making it harder to review. Please could you break it up into lots of small patches, each with good commit messages, and being obviously correct.

Quoted 1 line

+F: drivers/mfd/nct6694-hif.c

Maybe move all the usb code into nct6694-usb.c ?

drivers/gpio/gpio-nct6694.c line 18

Quoted 9 lines

- * USB command module type for NCT6694 GPIO controller.
- * This defines the module type used for communication with the NCT6694
- * GPIO controller over the USB interface.
- */

drivers/gpio/gpio-nct6694.c +0 -2
-#define NCT6694_GPIO_MOD	0xFF
-
 #define NCT6694_GPIO_VER	0x90
 #define NCT6694_GPIO_VALID	0x110
 #define NCT6694_GPI_DATA	0x120

Moving code from one place to another can be a patch. Just moving code is quick and easy to review, and it gets it out of more complex patches which are harder to review.

drivers/mfd/nct6694-hif.c line 283

Quoted 8 lines
drivers/mfd/nct6694-hif.c new file +8 -0
+static int nct6694_response_err_handling(struct nct6694 *nct6694, unsigned char err_status)
+{
+	switch (err_status) {
+	case NCT6694_NO_ERROR:
+		return 0;
+	case NCT6694_NOT_SUPPORT_ERROR:
+		dev_err(nct6694->dev, "Command is not supported!\n");
+		break;

Maybe EOPNOTSUPP?

drivers/mfd/nct6694-hif.c line 289

Quoted 6 lines
drivers/mfd/nct6694-hif.c new file +6 -0
+	case NCT6694_NO_RESPONSE_ERROR:
+		dev_warn(nct6694->dev, "Command received no response!\n");
+		break;
+	case NCT6694_TIMEOUT_ERROR:
+		dev_warn(nct6694->dev, "Command timed out!\n");
+		break;

Maybe ETIMEDOUT?

drivers/mfd/nct6694-hif.c line 292

Quoted 3 lines
drivers/mfd/nct6694-hif.c new file +3 -0
+	case NCT6694_PENDING:
+		dev_err(nct6694->dev, "Command is pending!\n");
+		break;

EBUSY?

Having different error codes can make it easier to debug when things so wrong. But you also have dev_err(), so it is less important.

drivers/mfd/nct6694.c static const struct mfd_cell nct6694_devs[] = { · line 83

Quoted 3 lines
drivers/mfd/nct6694.c +2 -1
-static int nct6694_response_err_handling(struct nct6694 *nct6694, unsigned char err_status)
+static int nct6694_usb_err_handling(struct nct6694 *nct6694,
+				    unsigned char err_status)

These renames can happen in one patch. Again, it is quick and easy to review.

Review

Quoted 3 lines
(quoted diff) +1 -1
-	guard(mutex)(&nct6694->access_lock);
+	guard(mutex)(&udata->access_lock);

This change is not obviously correct. Can moving the lock be made of patch of its own, with an explanation of why?

Quoted 11 lines
drivers/mfd/nct6694.c +4 -4
-	nct6694->usb_msg = devm_kzalloc(dev, sizeof(union nct6694_usb_msg), GFP_KERNEL);
-	if (!nct6694->usb_msg)
+	udata = devm_kzalloc(dev, sizeof(*udata), GFP_KERNEL);
+	if (!udata)
 		return -ENOMEM;
 
-	nct6694->int_buffer = devm_kzalloc(dev, sizeof(*nct6694->int_buffer), GFP_KERNEL);
-	if (!nct6694->int_buffer)
+	udata->usb_msg = devm_kzalloc(dev, sizeof(*udata->usb_msg), GFP_KERNEL);
+	if (!udata->usb_msg)
 		return -ENOMEM;

drivers/mfd/nct6694.c static int nct6694_usb_probe(struct usb_interface *iface, · line 330

Quoted 10 lines
drivers/mfd/nct6694.c +5 -2
 
-	nct6694->int_in_urb = usb_alloc_urb(0, GFP_KERNEL);
-	if (!nct6694->int_in_urb)
+	udata->int_buffer = devm_kzalloc(dev, sizeof(*udata->int_buffer), GFP_KERNEL);
+	if (!udata->int_buffer)
 		return -ENOMEM;
 
+	udata->int_in_urb = usb_alloc_urb(0, GFP_KERNEL);
+	if (!udata->int_in_urb)
+		return -ENOMEM;

In this hunk, diff(1) has done a poor job and made it harder to review. If i understand the code correctly, udata contains USB specific data? Maybe call it usdata? That also has the same length as ntc6694, which has some minor advantages. What you might find is that if you have a patch adding only the allocation of usbdata, and then a patch moving things into usbdata, diff(1) does a better job, and the code is more obviously correct.

Quoted 5 lines
drivers/mfd/nct6694.c +0 -1
@@ -305,16 +344,15 @@ static int nct6694_usb_probe(struct usb_interface *iface,
 	}
 
 	nct6694->dev = dev;
-	nct6694->udev = udev;

drivers/mfd/nct6694.c static int nct6694_usb_probe(struct usb_interface *iface, · line 316

Quoted 10 lines
drivers/mfd/nct6694.c +2 -2
+
+	spin_lock_init(&nct6694->irq_lock);
 
 	ida_init(&nct6694->gpio_ida);
 	ida_init(&nct6694->i2c_ida);
 	ida_init(&nct6694->canfd_ida);
 	ida_init(&nct6694->wdt_ida);
 
-	spin_lock_init(&nct6694->irq_lock);
-

Why has the spin_lock_init() moved? Having lots of small patches would make that stand out, and when you reviewed your own patches, you might decided to change it back, because it does not appear to be needed.

Given the size of this patch, i'm finding it hard to see the overall structure. Generally, when you have one device with two different access mechanisms, you end up with three files, two implementing access, and the third with the common code. With one big patch, i don't see this common code.

Andrew

maintainer
#3 lore raw

Re: [PATCH v4 1/1] mfd: Add Host Interface (HIF) support for Nuvoton NCT6694

Quoted 10 lines · Andrew Lunn
Quoted 9 lines
  MAINTAINERS                         |   1 +
  drivers/gpio/gpio-nct6694.c         |   7 -
  drivers/hwmon/nct6694-hwmon.c       |  21 -
  drivers/i2c/busses/i2c-nct6694.c    |   7 -
  drivers/mfd/Kconfig                 |  47 +-
  drivers/mfd/Makefile                |   3 +-
  drivers/mfd/nct6694-hif.c           | 663 ++++++++++++++++++++++++++++
  drivers/mfd/nct6694.c               | 111 +++--
  drivers/net/can/usb/nct6694_canfd.c |   6 -
Quoted 8 lines

The networking change here is very small, so my influence as a networking Maintainer should be considered small.

However, i would say this patch is too big, does too many different things at once, making it harder to review. Please could you break it up into lots of small patches, each with good commit messages, and being obviously correct.

Add my influence as hardware monitoring maintainer. I very much agree.

Guenter

#4 lore raw

Re: [PATCH v4 1/1] mfd: Add Host Interface (HIF) support for Nuvoton NCT6694

In reply to [email protected]
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider: - [Critical] Calling devm_request_threaded_irq() with a NULL primary handler and IRQF_SHARED…

Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:
- [Critical] Calling devm_request_threaded_irq() with a NULL primary handler and IRQF_SHARED unconditionally fails.
- [High] The Linux virtual IRQ number is incorrectly written to the hardware Super-I/O IRQ routing register.
- [High] USB transfer buffers are allocated with devm_kzalloc(), violating DMA cacheline alignment requirements.
- [High] Hardware interrupts are enabled before the IRQ handler is registered, and disabled after the handler is freed, creating a window for unhandled interrupt storms.
- [High] Missing bounds check on interface->endpoint array before accessing the first endpoint in the USB probe function.
- [High] The USB interrupt callback ignores urb->actual_length, risking reading uninitialized or stale memory.
- [High] Returning IRQ_NONE after successfully acknowledging the device's interrupt in the HIF IRQ handler.
- [High] Software-only IRQ masking causes an interrupt storm if a child device's IRQ is disabled by the OS.
--

commit 719984a8b6993b3c3d29315e4713194e4c4a7af4
Author: Ming Yu <[email protected]>

mfd: Add Host Interface (HIF) support for Nuvoton NCT6694

The Nuvoton NCT6694 provides a Host Interface (HIF) via eSPI. This commit updates the driver configuration to allow selecting between the USB and HIF interfaces, sharing common functions and sub-devices.

Quoted 5 lines
drivers/mfd/nct6694-hif.c new file +0 -0
new file mode 100644
index 0000000000000..ca8c08b0d2e34

[ ... ]

Quoted 9 lines
drivers/mfd/nct6694-hif.c new file +9 -0
+static irqreturn_t nct6694_irq_handler(int irq, void *data)
+{
+	struct nct6694 *nct6694 = data;
+	struct nct6694_hif_data *hdata = nct6694->priv;
+	u8 reg_data[4];
+	u32 intr_status;
+	int ret;
+
+	/* Check interrupt status is set */

drivers/mfd/nct6694-hif.c line 422

Quoted 10 lines
drivers/mfd/nct6694-hif.c new file +10 -0
+	if (!(inb(hdata->shm_base + NCT6694_SHM_COFS_STS) & NCT6694_SHM_COFS_STS_COFS4W))
+		return IRQ_NONE;
+
+	/* Clear interrupt status */
+	outb(NCT6694_SHM_COFS_STS_COFS4W, hdata->shm_base + NCT6694_SHM_COFS_STS);
+
+	ret = regmap_bulk_read(hdata->regmap, NCT6694_SHM_INTR_STATUS,
+			       reg_data, ARRAY_SIZE(reg_data));
+	if (ret)
+		return IRQ_NONE;

Is it correct to return IRQ_NONE here?

The driver has already verified the interrupt belongs to the device and cleared it at the hardware level.

Should this return IRQ_HANDLED instead to prevent misleading the kernel's spurious interrupt detector?

[ ... ]

Quoted 12 lines
drivers/mfd/nct6694-hif.c new file +12 -0
+static int nct6694_irq_init(struct nct6694 *nct6694, int irq)
+{
+	struct nct6694_hif_data *hdata = nct6694->priv;
+	struct nct6694_sio_data *sio_data = hdata->sio_data;
+	unsigned char cofs_ctl2;
+	int ret;
+
+	/* Set SIRQ number */
+	ret = superio_enter(sio_data);
+	if (ret)
+		return ret;
+

drivers/mfd/nct6694-hif.c line 471

Quoted 10 lines
drivers/mfd/nct6694-hif.c new file +10 -0
+	superio_select(sio_data, SIO_REG_LD_SHM);
+
+	if (!superio_inb(sio_data, SIO_REG_SHM_ENABLE)) {
+		superio_exit(sio_data);
+		return -EIO;
+	}
+
+	hdata->shm_base = superio_inw(sio_data, SIO_REG_SHM_BASE_ADDR);
+
+	superio_outb(sio_data, SIO_REG_SHM_IRQ_NR, irq);

Does irq hold a Linux virtual IRQ number here?

platform_get_irq() returns a Linux-internal virtual IRQ number (virq), while the Super-I/O hardware configuration register typically expects a physical ISA IRQ routing number (e.g. 0-15).

Could writing a virtual IRQ number misconfigure the hardware?

[ ... ]

drivers/mfd/nct6694-hif.c line 501

Quoted 9 lines
drivers/mfd/nct6694-hif.c new file +9 -0
+static void nct6694_irq_disable(struct irq_data *data)
+{
+	struct nct6694 *nct6694 = irq_data_get_irq_chip_data(data);
+	irq_hw_number_t hwirq = irqd_to_hwirq(data);
+
+	guard(spinlock_irqsave)(&nct6694->irq_lock);
+
+	nct6694->irq_enable &= ~BIT(hwirq);
+}

Could this software-only IRQ masking cause an interrupt storm?

If a child device's IRQ is disabled by the OS, nct6694->irq_enable is updated but the interrupt is not masked at the hardware level.

Since the top-level handler nct6694_irq_handler() dispatches interrupts via generic_handle_irq_safe(), which ignores irq_enable, could the device immediately reassert the interrupt if the child handler never runs to clear the hardware condition?

[ ... ]

Quoted 2 lines
drivers/mfd/nct6694-hif.c new file +2 -0
+static int nct6694_probe(struct platform_device *pdev)
+{

[ ... ]

drivers/mfd/nct6694-hif.c line 633

Quoted 11 lines
drivers/mfd/nct6694-hif.c new file +11 -0
+	ret = nct6694_irq_init(data, irq);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action_or_reset(dev, nct6694_irq_release, data);
+	if (ret)
+		return ret;
+
+	ret = devm_request_threaded_irq(dev, irq, NULL, nct6694_irq_handler,
+					IRQF_ONESHOT | IRQF_SHARED,
+					dev_name(dev), data);

Does this sequence create a window for unhandled interrupt storms?

nct6694_irq_init() enables interrupts on the device hardware, and the OS handler is requested afterwards. Similarly, because devres unwinds in reverse order, the OS handler will be freed before the hardware interrupt is disabled during removal.

Also, can devm_request_threaded_irq() succeed here?

The Linux interrupt core explicitly rejects requests for shared interrupts (IRQF_SHARED) with a NULL primary hardirq handler, returning -EINVAL.

Quoted 4 lines
drivers/mfd/nct6694.c +0 -0
index 308b2fda3055c..cf3457c2b3ed2 100644

[ ... ]

drivers/mfd/nct6694.c static void usb_int_callback(struct urb *urb) · line 240

Quoted 7 lines
drivers/mfd/nct6694.c +2 -1
@@ -210,10 +236,12 @@ static void usb_int_callback(struct urb *urb)
 	int_status = le32_to_cpu(*status_le);
 
 	while (int_status) {
-		int irq = __ffs(int_status);
+		int hwirq = __ffs(int_status);
+		unsigned int virq = irq_find_mapping(nct6694->domain, hwirq);

Is it safe to read *status_le without checking urb->actual_length?

If a buggy or malicious USB device sends a short packet or a Zero-Length Packet (ZLP), could the driver read uninitialized or stale data from the transfer buffer?

[ ... ]

Quoted 11 lines
drivers/mfd/nct6694.c +2 -3
@@ -284,18 +313,28 @@ static int nct6694_usb_probe(struct usb_interface *iface,
 	if (!nct6694)
 		return -ENOMEM;
 
-	nct6694->usb_msg = devm_kzalloc(dev, sizeof(union nct6694_usb_msg), GFP_KERNEL);
-	if (!nct6694->usb_msg)
+	udata = devm_kzalloc(dev, sizeof(*udata), GFP_KERNEL);
+	if (!udata)
 		return -ENOMEM;
 
-	nct6694->int_buffer = devm_kzalloc(dev, sizeof(*nct6694->int_buffer), GFP_KERNEL);

drivers/mfd/nct6694.c static int nct6694_usb_probe(struct usb_interface *iface, · line 326

Quoted 10 lines
drivers/mfd/nct6694.c +4 -3
-	if (!nct6694->int_buffer)
+	udata->usb_msg = devm_kzalloc(dev, sizeof(*udata->usb_msg), GFP_KERNEL);
+	if (!udata->usb_msg)
 		return -ENOMEM;
 
-	nct6694->int_in_urb = usb_alloc_urb(0, GFP_KERNEL);
-	if (!nct6694->int_in_urb)
+	udata->int_buffer = devm_kzalloc(dev, sizeof(*udata->int_buffer), GFP_KERNEL);
+	if (!udata->int_buffer)
 		return -ENOMEM;

Is it safe to allocate USB DMA transfer buffers using devm_kzalloc()?

Memory allocated via devm_kzalloc() is prefixed with a devres header, causing the actual payload to be unaligned to ARCH_DMA_MINALIGN.

Could this lead to cache invalidation wiping out concurrent CPU updates to the adjacent devres header on architectures with non-coherent DMA? Should standard kmalloc() be used instead?

[ ... ]

drivers/mfd/nct6694.c static int nct6694_usb_probe(struct usb_interface *iface, · line 369

Quoted 9 lines
drivers/mfd/nct6694.c +2 -2
@@ -326,11 +364,11 @@ static int nct6694_usb_probe(struct usb_interface *iface,
 		goto err_ida;
 	}
 
-	usb_fill_int_urb(nct6694->int_in_urb, udev, usb_rcvintpipe(udev, NCT6694_INT_IN_EP),
-			 nct6694->int_buffer, sizeof(*nct6694->int_buffer), usb_int_callback,
+	usb_fill_int_urb(udata->int_in_urb, udev, usb_rcvintpipe(udev, NCT6694_INT_IN_EP),
+			 udata->int_buffer, sizeof(*udata->int_buffer), usb_int_callback,
 			 nct6694, int_endpoint->bInterval);

Does the code verify that the interface has any endpoints configured before accessing &interface->endpoint[0].desc to set int_endpoint earlier in the probe function?

If a malformed USB device exposes an interface with zero endpoints, could accessing endpoint[0] result in an out-of-bounds read?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1