Skip to contentSkip to conversation

mfd: wcd934x: set DMA mask on parent to silence "DMA mask not set"

PATCH Applied David Heidelberg 3 participants 4 messages Sep 3 – Sep 10

Subsystems (2)

v2 of 3 Applied Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mfd: wcd934x: set DMA mask on parent to silence "DMA mask not set"

The wcd934x MFD parent (a slim_device) never initializes its dma_mask/coherent_dma_mask. When the DT-aware children pass through of_dma_configure() this triggers the "DMA mask not set" warning for each child.

Fixes f959dcd6ddfd ("dma-direct: Fix potential NULL pointer dereference")
Assisted-by tencent:hy3

---
Changes in v2:
- Use dma_coerce_mask_and_coherent. (Lee)
- Link to v1: https://patch.msgid.link/[email protected]

---
 drivers/mfd/wcd934x.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/mfd/wcd934x.c +6 -0
index 3c3080e8c8cf7..853edda9b6da7 100644
@@ -1,12 +1,13 @@
 // SPDX-License-Identifier: GPL-2.0
 // Copyright (c) 2019, Linaro Limited
 
 #include <linux/clk.h>
+#include <linux/dma-mapping.h>
 #include <linux/gpio/consumer.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/mfd/core.h>
 #include <linux/mfd/wcd934x/registers.h>
 #include <linux/mfd/wcd934x/wcd934x.h>
 #include <linux/module.h>
 #include <linux/of.h>
@@ -212,16 +213,21 @@ static int wcd934x_slim_status(struct slim_device *sdev,
 static int wcd934x_slim_probe(struct slim_device *sdev)
 {
 	struct device *dev = &sdev->dev;
 	struct device_node *np = dev->of_node;
 	struct wcd934x_ddata *ddata;
 	struct gpio_desc *reset_gpio;
 	int ret;
 
+	ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "Failed to set dma mask\n");
+
 	ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
 	if (!ddata)
 		return	-ENOMEM;
 
 	ddata->irq = of_irq_get(np, 0);
 	if (ddata->irq < 0)
 		return dev_err_probe(ddata->dev, ddata->irq,
 				     "Failed to get IRQ\n");

---
base-commit: 7079a12d7506b07fb53b54a664bfad5fa9b16d70
change-id: 20260823-wcd-dma-bd621ee39887

Best regards,

Signature · 1 line
David Heidelberg <[email protected]>
#1 lore raw
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [Low] The commit message description is not capitalized, violating MFD subsystem guidelines.

Pre-existing issues:
- [High] Passing an uninitialized ddata->dev to dev_err_probe causes a NULL pointer dereference if of_irq_get fails.
- [High] Improper usage of devm_regmap_add_irq_chip() in a dynamic callback leads to devres leaks and double registrations. --

commit 8dc8a0470b92c9050119b56c1d1e8f85a3dcc721
Author: David Heidelberg <[email protected]>

mfd: wcd934x: set DMA mask on parent to silence "DMA mask not set"

The wcd934x MFD parent (a slim_device) never initializes its dma_mask/coherent_dma_mask. When the DT-aware children pass through of_dma_configure() this triggers the "DMA mask not set" warning for each child.

Quoted 1 line

mfd: wcd934x: set DMA mask on parent to silence "DMA mask not set"

[Severity: Low]
This isn't a bug, but does the commit message follow the MFD subsystem formatting rules? The guidelines require the description after the subsystem prefix to be capitalized, but "set" starts with a lowercase letter.

Quoted 6 lines
drivers/mfd/wcd934x.c +0 -0
index 3c3080e8c8cf7..853edda9b6da7 100644
@@ -217,6 +218,11 @@ static int wcd934x_slim_probe(struct slim_device *sdev)
 	struct gpio_desc *reset_gpio;

drivers/mfd/wcd934x.c static int wcd934x_slim_probe(struct slim_device *sdev) · line 228

Quoted 10 lines
drivers/mfd/wcd934x.c +5 -0
 	int ret;
 
+	ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "Failed to set dma mask\n");
+
 	ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
 	if (!ddata)
 		return	-ENOMEM;

[Severity: High]
This isn't a bug introduced by this patch, but can this cause a NULL pointer dereference further down in wcd934x_slim_probe()?

If of_irq_get() fails, the error path passes ddata->dev to dev_err_probe():

drivers/mfd/wcd934x.c:wcd934x_slim_probe() {
    ...
	ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
	if (!ddata)
		return	-ENOMEM;

	ddata->irq = of_irq_get(np, 0);
	if (ddata->irq < 0)
		return dev_err_probe(ddata->dev, ddata->irq,
				     "Failed to get IRQ\n");
    ...
}

Since ddata was just allocated with devm_kzalloc(), ddata->dev is NULL. When dev_err_probe() passes this down to __dev_probe_failed(), it dereferences the NULL pointer.

[Severity: High]
This is a pre-existing issue, but does the use of managed devres functions in wcd934x_slim_status_up() cause memory leaks and double registrations?

drivers/mfd/wcd934x.c:wcd934x_slim_status_up() {
    ...
	ret = devm_regmap_add_irq_chip(dev, ddata->regmap, ddata->irq,
				       IRQF_TRIGGER_HIGH, 0,
				       &wcd934x_regmap_irq_chip,
				       &ddata->irq_data);
    ...
}

wcd934x_slim_status_up() is called when the SLIMbus transitions to SLIM_DEVICE_STATUS_UP. If the bus goes DOWN, mfd_remove_devices() is called, but the IRQ chip added via devm_regmap_add_irq_chip() is not removed because devres cleanup only happens on driver unbind, not on bus status changes.

When the bus transitions UP again, wouldn't the driver attempt to re-register the IRQ chip and fail with -EBUSY, leaving the device in an unusable state?

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

Re: (subset) [PATCH v2] mfd: wcd934x: set DMA mask on parent to silence "DMA mask not set"

In reply to David Heidelberg
Quoted 4 lines · David Heidelberg

The wcd934x MFD parent (a slim_device) never initializes its dma_mask/coherent_dma_mask. When the DT-aware children pass through of_dma_configure() this triggers the "DMA mask not set" warning for each child.

Applied, thanks!

[1/1] mfd: wcd934x: set DMA mask on parent to silence "DMA mask not set"

      commit: 5a5f978cf3cd2f50b9e123f851f5c6577519ee89

--
Lee Jones [李琼斯]

maintainer
#3 lore raw

Re: (subset) [PATCH v2] mfd: wcd934x: set DMA mask on parent to silence "DMA mask not set"

Quoted 10 lines · Lee Jones
Quoted 4 lines · David Heidelberg

The wcd934x MFD parent (a slim_device) never initializes its dma_mask/coherent_dma_mask. When the DT-aware children pass through of_dma_configure() this triggers the "DMA mask not set" warning for each child.

Applied, thanks!

[1/1] mfd: wcd934x: set DMA mask on parent to silence "DMA mask not set"

      commit: 5a5f978cf3cd2f50b9e123f851f5c6577519ee89

Note that I changed s/dma/DMA/ when applying.

Signature · 1 line
Lee Jones