Skip to contentSkip to conversation

xhci: dbc: Drop duplicate checks for dma_free_coherent()

PATCH Superseded Andy Shevchenko 3 participants 15 messages Oct 2, 2023 – Oct 11, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/10 xhci: dbc: Drop duplicate checks for dma_free_coherent()

dma_free_coherent() is NULL-aware, not necessary to check for the parameter twice. Drop duplicate conditionals in the caller.

---
 drivers/usb/host/xhci-dbgcap.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/usb/host/xhci-dbgcap.c +5 -9
index b40d9238d447..9e9ce3711813 100644
@@ -28,7 +28,7 @@ static void dbc_ring_free(struct device *dev, struct xhci_ring *ring)
 	if (!ring)
 		return;
 
-	if (ring->first_seg && ring->first_seg->trbs) {
+	if (ring->first_seg) {
 		dma_free_coherent(dev, TRB_SEGMENT_SIZE,
 				  ring->first_seg->trbs,
 				  ring->first_seg->dma);
@@ -394,9 +394,8 @@ static int dbc_erst_alloc(struct device *dev, struct xhci_ring *evt_ring,
 
 static void dbc_erst_free(struct device *dev, struct xhci_erst *erst)
 {
-	if (erst->entries)
-		dma_free_coherent(dev, sizeof(struct xhci_erst_entry),
-				  erst->entries, erst->erst_dma_addr);
+	dma_free_coherent(dev, sizeof(struct xhci_erst_entry), erst->entries,
+			  erst->erst_dma_addr);
 	erst->entries = NULL;
 }
 
@@ -543,11 +542,8 @@ static void xhci_dbc_mem_cleanup(struct xhci_dbc *dbc)
 
 	xhci_dbc_eps_exit(dbc);
 
-	if (dbc->string) {
-		dma_free_coherent(dbc->dev, dbc->string_size,
-				  dbc->string, dbc->string_dma);
-		dbc->string = NULL;
-	}
+	dma_free_coherent(dbc->dev, dbc->string_size, dbc->string, dbc->string_dma);
+	dbc->string = NULL;
 
 	dbc_free_ctx(dbc->dev, dbc->ctx);
 	dbc->ctx = NULL;
Signature · 1 line
2.40.0.1.gaa8946217a0b
#1 lore raw

PATCH 2/10 xhci: dbc: Convert to use sysfs_streq()

It's standard approach to parse values from user space by using sysfs_streq(). Make driver use it.

---
 drivers/usb/host/xhci-dbgcap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/host/xhci-dbgcap.c +2 -2
index 9e9ce3711813..f505b79afe53 100644
@@ -957,9 +957,9 @@ static ssize_t dbc_store(struct device *dev,
 	xhci = hcd_to_xhci(dev_get_drvdata(dev));
 	dbc = xhci->dbc;
 
-	if (!strncmp(buf, "enable", 6))
+	if (sysfs_streq(buf, "enable"))
 		xhci_dbc_start(dbc);
-	else if (!strncmp(buf, "disable", 7))
+	else if (sysfs_streq(buf, "disable"))
 		xhci_dbc_stop(dbc);
 	else
 		return -EINVAL;
Signature · 1 line
2.40.0.1.gaa8946217a0b
#2 lore raw

PATCH 3/10 xhci: dbc: Use sysfs_emit() to instead of scnprintf()

In reply to Andy Shevchenko

Follow the advice of the Documentation/filesystems/sysfs.rst and show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.

---
 drivers/usb/host/xhci-dbgcap.c | 43 +++++++++++++---------------------
 drivers/usb/host/xhci-dbgcap.h |  1 +
 2 files changed, 17 insertions(+), 27 deletions(-)
drivers/usb/host/xhci-dbgcap.c +16 -27
index f505b79afe53..92869c67a430 100644
@@ -910,6 +910,15 @@ static void xhci_dbc_handle_events(struct work_struct *work)
 	mod_delayed_work(system_wq, &dbc->event_work, 1);
 }
 
+static const char * const dbc_state_strings[DS_MAX] = {
+	[DS_DISABLED] = "disabled",
+	[DS_INITIALIZED] = "initialized",
+	[DS_ENABLED] = "enabled",
+	[DS_CONNECTED] = "connected",
+	[DS_CONFIGURED] = "configured",
+	[DS_STALLED] = "stalled",
+};
+
 static ssize_t dbc_show(struct device *dev,
 			struct device_attribute *attr,
 			char *buf)
@@ -921,30 +930,10 @@ static ssize_t dbc_show(struct device *dev,
 	xhci = hcd_to_xhci(dev_get_drvdata(dev));
 	dbc = xhci->dbc;
 
-	switch (dbc->state) {
-	case DS_DISABLED:
-		p = "disabled";
-		break;
-	case DS_INITIALIZED:
-		p = "initialized";
-		break;
-	case DS_ENABLED:
-		p = "enabled";
-		break;
-	case DS_CONNECTED:
-		p = "connected";
-		break;
-	case DS_CONFIGURED:
-		p = "configured";
-		break;
-	case DS_STALLED:
-		p = "stalled";
-		break;
-	default:
-		p = "unknown";
-	}
+	if (dbc->state >= ARRAY_SIZE(dbc_state_strings))
+		return sysfs_emit(buf, "unknown\n");
 
-	return sprintf(buf, "%s\n", p);
+	return sysfs_emit(buf, "%s\n", dbc_state_strings[dbc->state]);
 }
 
 static ssize_t dbc_store(struct device *dev,
@@ -977,7 +966,7 @@ static ssize_t dbc_idVendor_show(struct device *dev,
 	xhci = hcd_to_xhci(dev_get_drvdata(dev));
 	dbc = xhci->dbc;
 
-	return sprintf(buf, "%04x\n", dbc->idVendor);
+	return sysfs_emit(buf, "%04x\n", dbc->idVendor);
 }
 
 static ssize_t dbc_idVendor_store(struct device *dev,
@@ -1017,7 +1006,7 @@ static ssize_t dbc_idProduct_show(struct device *dev,
 	xhci = hcd_to_xhci(dev_get_drvdata(dev));
 	dbc = xhci->dbc;
 
-	return sprintf(buf, "%04x\n", dbc->idProduct);
+	return sysfs_emit(buf, "%04x\n", dbc->idProduct);
 }
 
 static ssize_t dbc_idProduct_store(struct device *dev,
@@ -1056,7 +1045,7 @@ static ssize_t dbc_bcdDevice_show(struct device *dev,
 	xhci = hcd_to_xhci(dev_get_drvdata(dev));
 	dbc = xhci->dbc;
 
-	return sprintf(buf, "%04x\n", dbc->bcdDevice);
+	return sysfs_emit(buf, "%04x\n", dbc->bcdDevice);
 }
 
 static ssize_t dbc_bcdDevice_store(struct device *dev,
@@ -1096,7 +1085,7 @@ static ssize_t dbc_bInterfaceProtocol_show(struct device *dev,
 	xhci = hcd_to_xhci(dev_get_drvdata(dev));
 	dbc = xhci->dbc;
 
-	return sprintf(buf, "%02x\n", dbc->bInterfaceProtocol);
+	return sysfs_emit(buf, "%02x\n", dbc->bInterfaceProtocol);
 }
 
 static ssize_t dbc_bInterfaceProtocol_store(struct device *dev,
drivers/usb/host/xhci-dbgcap.h +1 -0
index 51a7ab3ba0ca..e39e3ae1677a 100644
@@ -82,6 +82,7 @@ enum dbc_state {
 	DS_CONNECTED,
 	DS_CONFIGURED,
 	DS_STALLED,
+	DS_MAX
 };
 
 struct dbc_ep {
Signature · 1 line
2.40.0.1.gaa8946217a0b
#3 lore raw

Re: [PATCH v1 03/10] xhci: dbc: Use sysfs_emit() to instead of scnprintf()

kernel test robot noticed the following build warnings:

Hi Andy,

kernel test robot noticed the following build warnings:

[auto build test WARNING on usb/usb-testing]
[also build test WARNING on usb/usb-next usb/usb-linus linus/master v6.6-rc4 next-20230929] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/xhci-dbc-Convert-to-use-sysfs_streq/20231003-002032
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
patch link:    https://lore.kernel.org/r/20231002161610.2648818-3-andriy.shevchenko%40linux.intel.com
patch subject: [PATCH v1 03/10] xhci: dbc: Use sysfs_emit() to instead of scnprintf()
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20231003/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231003/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/usb/host/xhci-dbgcap.c: In function 'dbc_show':

>> drivers/usb/host/xhci-dbgcap.c:926:34: warning: unused variable 'p' [-Wunused-variable]
     926 |         const char              *p;
         |                                  ^

vim +/p +926 drivers/usb/host/xhci-dbgcap.c

60f4451ef37351 Andy Shevchenko 2023-10-02  921  
dfba2174dc421e Lu Baolu        2017-12-08  922  static ssize_t dbc_show(struct device *dev,
dfba2174dc421e Lu Baolu        2017-12-08  923  			struct device_attribute *attr,
dfba2174dc421e Lu Baolu        2017-12-08  924  			char *buf)
dfba2174dc421e Lu Baolu        2017-12-08  925  {
dfba2174dc421e Lu Baolu        2017-12-08 @926  	const char		*p;
dfba2174dc421e Lu Baolu        2017-12-08  927  	struct xhci_dbc		*dbc;
dfba2174dc421e Lu Baolu        2017-12-08  928  	struct xhci_hcd		*xhci;
dfba2174dc421e Lu Baolu        2017-12-08  929  
dfba2174dc421e Lu Baolu        2017-12-08  930  	xhci = hcd_to_xhci(dev_get_drvdata(dev));
dfba2174dc421e Lu Baolu        2017-12-08  931  	dbc = xhci->dbc;
dfba2174dc421e Lu Baolu        2017-12-08  932  
60f4451ef37351 Andy Shevchenko 2023-10-02  933  	if (dbc->state >= ARRAY_SIZE(dbc_state_strings))
60f4451ef37351 Andy Shevchenko 2023-10-02  934  		return sysfs_emit(buf, "unknown\n");
dfba2174dc421e Lu Baolu        2017-12-08  935  
60f4451ef37351 Andy Shevchenko 2023-10-02  936  	return sysfs_emit(buf, "%s\n", dbc_state_strings[dbc->state]);
dfba2174dc421e Lu Baolu        2017-12-08  937  }
dfba2174dc421e Lu Baolu        2017-12-08  938  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw

Re: [PATCH v1 03/10] xhci: dbc: Use sysfs_emit() to instead of scnprintf()

Quoted 6 lines · kernel test robot

All warnings (new ones prefixed by >>):

drivers/usb/host/xhci-dbgcap.c: In function 'dbc_show':

Quoted 1 line
Quoted 1 line

drivers/usb/host/xhci-dbgcap.c:926:34: warning: unused variable 'p' [-Wunused-variable]

     926 |         const char              *p;
         |                                  ^

Indeed, forgot to remove it...

Mathias, tell me if you want a v2 of this patch or the entire series.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

Re: [PATCH v1 03/10] xhci: dbc: Use sysfs_emit() to instead of scnprintf()

Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · kernel test robot

All warnings (new ones prefixed by >>):

Quoted 9 lines
Quoted 4 lines

drivers/usb/host/xhci-dbgcap.c: In function 'dbc_show':

Quoted 1 line
Quoted 1 line

drivers/usb/host/xhci-dbgcap.c:926:34: warning: unused variable 'p' [-Wunused-variable]

      926 |         const char              *p;
          |                                  ^

Indeed, forgot to remove it...

Mathias, tell me if you want a v2 of this patch or the entire series.

No need, I can fix this while applying

Thanks
Mathias

#6 lore raw

PATCH 4/10 xhci: dbc: Use ATTRIBUTE_GROUPS()

In reply to Andy Shevchenko

Embrace ATTRIBUTE_GROUPS() to avoid boiler plate code. This should not introduce any functional changes.

---
 drivers/usb/host/xhci-dbgcap.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/usb/host/xhci-dbgcap.c +4 -7
index 92869c67a430..3c90410e9cde 100644
@@ -1124,7 +1124,7 @@ static DEVICE_ATTR_RW(dbc_idProduct);
 static DEVICE_ATTR_RW(dbc_bcdDevice);
 static DEVICE_ATTR_RW(dbc_bInterfaceProtocol);
 
-static struct attribute *dbc_dev_attributes[] = {
+static struct attribute *dbc_dev_attrs[] = {
 	&dev_attr_dbc.attr,
 	&dev_attr_dbc_idVendor.attr,
 	&dev_attr_dbc_idProduct.attr,
@@ -1132,10 +1132,7 @@ static struct attribute *dbc_dev_attributes[] = {
 	&dev_attr_dbc_bInterfaceProtocol.attr,
 	NULL
 };
-
-static const struct attribute_group dbc_dev_attrib_grp = {
-	.attrs = dbc_dev_attributes,
-};
+ATTRIBUTE_GROUPS(dbc_dev);
 
 struct xhci_dbc *
 xhci_alloc_dbc(struct device *dev, void __iomem *base, const struct dbc_driver *driver)
@@ -1161,7 +1158,7 @@ xhci_alloc_dbc(struct device *dev, void __iomem *base, const struct dbc_driver *
 	INIT_DELAYED_WORK(&dbc->event_work, xhci_dbc_handle_events);
 	spin_lock_init(&dbc->lock);
 
-	ret = sysfs_create_group(&dev->kobj, &dbc_dev_attrib_grp);
+	ret = sysfs_create_groups(&dev->kobj, &dbc_dev_groups);
 	if (ret)
 		goto err;
 
@@ -1180,7 +1177,7 @@ void xhci_dbc_remove(struct xhci_dbc *dbc)
 	xhci_dbc_stop(dbc);
 
 	/* remove sysfs files */
-	sysfs_remove_group(&dbc->dev->kobj, &dbc_dev_attrib_grp);
+	sysfs_remove_groups(&dbc->dev->kobj, &dbc_dev_groups);
 
 	kfree(dbc);
 }
Signature · 1 line
2.40.0.1.gaa8946217a0b
#7 lore raw

Re: [PATCH v1 04/10] xhci: dbc: Use ATTRIBUTE_GROUPS()

Quoted 34 lines · Andy Shevchenko

Embrace ATTRIBUTE_GROUPS() to avoid boiler plate code. This should not introduce any functional changes.

---
  drivers/usb/host/xhci-dbgcap.c | 11 ++++-------
  1 file changed, 4 insertions(+), 7 deletions(-)
drivers/usb/host/xhci-dbgcap.c +2 -5
index 92869c67a430..3c90410e9cde 100644
@@ -1124,7 +1124,7 @@ static DEVICE_ATTR_RW(dbc_idProduct);
  static DEVICE_ATTR_RW(dbc_bcdDevice);
  static DEVICE_ATTR_RW(dbc_bInterfaceProtocol);
 
-static struct attribute *dbc_dev_attributes[] = {
+static struct attribute *dbc_dev_attrs[] = {
  	&dev_attr_dbc.attr,
  	&dev_attr_dbc_idVendor.attr,
  	&dev_attr_dbc_idProduct.attr,
@@ -1132,10 +1132,7 @@ static struct attribute *dbc_dev_attributes[] = {
  	&dev_attr_dbc_bInterfaceProtocol.attr,
  	NULL
  };
-
-static const struct attribute_group dbc_dev_attrib_grp = {
-	.attrs = dbc_dev_attributes,
-};
+ATTRIBUTE_GROUPS(dbc_dev);
 
  struct xhci_dbc *
  xhci_alloc_dbc(struct device *dev, void __iomem *base, const struct dbc_driver *driver)

drivers/usb/host/xhci-dbgcap.c xhci_alloc_dbc(struct device *dev, void __iomem *base, const struct dbc_driver * · line 1161

Quoted 5 lines
drivers/usb/host/xhci-dbgcap.c +1 -1
@@ -1161,7 +1158,7 @@ xhci_alloc_dbc(struct device *dev, void __iomem *base, const struct dbc_driver *
  	INIT_DELAYED_WORK(&dbc->event_work, xhci_dbc_handle_events);
  	spin_lock_init(&dbc->lock);
 
-	ret = sysfs_create_group(&dev->kobj, &dbc_dev_attrib_grp);
+	ret = sysfs_create_groups(&dev->kobj, &dbc_dev_groups)  

Compiler warns:

drivers/usb/host/xhci-dbgcap.c:1186:40: error: passing argument 2 of ‘sysfs_create_groups’ from incompatible pointer type

should probably be:
sysfs_create_groups(&dev->kobj, dbc_dev_groups)

-Mathias

#8 lore raw

PATCH 5/10 xhci: dbc: Check for errors first in xhci_dbc_stop()

In reply to Andy Shevchenko

The usual patter is to check for errors and then continue if none. Apply that pattern to xhci_dbc_stop() code.

---
 drivers/usb/host/xhci-dbgcap.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/host/xhci-dbgcap.c +4 -4
index 3c90410e9cde..d110eb5f1625 100644
@@ -646,11 +646,11 @@ static void xhci_dbc_stop(struct xhci_dbc *dbc)
 	spin_lock_irqsave(&dbc->lock, flags);
 	ret = xhci_do_dbc_stop(dbc);
 	spin_unlock_irqrestore(&dbc->lock, flags);
+	if (ret)
+		return;
 
-	if (!ret) {
-		xhci_dbc_mem_cleanup(dbc);
-		pm_runtime_put_sync(dbc->dev); /* note, was self.controller */
-	}
+	xhci_dbc_mem_cleanup(dbc);
+	pm_runtime_put_sync(dbc->dev); /* note, was self.controller */
 }
 
 static void
Signature · 1 line
2.40.0.1.gaa8946217a0b
#9 lore raw

PATCH 6/10 xhci: dbc: Don't shadow error codes in store() functions

In reply to Andy Shevchenko

kstrtox() along with regmap API can return different error codes based on the circumstances. Don't shadow them when returning to the caller.

---
 drivers/usb/host/xhci-dbgcap.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
drivers/usb/host/xhci-dbgcap.c +18 -8
index d110eb5f1625..2332133c6581 100644
@@ -978,9 +978,11 @@ static ssize_t dbc_idVendor_store(struct device *dev,
 	void __iomem		*ptr;
 	u16			value;
 	u32			dev_info;
+	int ret;
 
-	if (kstrtou16(buf, 0, &value))
-		return -EINVAL;
+	ret = kstrtou16(buf, 0, &value);
+	if (ret)
+		return ret;
 
 	xhci = hcd_to_xhci(dev_get_drvdata(dev));
 	dbc = xhci->dbc;
@@ -1018,9 +1020,11 @@ static ssize_t dbc_idProduct_store(struct device *dev,
 	void __iomem		*ptr;
 	u32			dev_info;
 	u16			value;
+	int ret;
 
-	if (kstrtou16(buf, 0, &value))
-		return -EINVAL;
+	ret = kstrtou16(buf, 0, &value);
+	if (ret)
+		return ret;
 
 	xhci = hcd_to_xhci(dev_get_drvdata(dev));
 	dbc = xhci->dbc;
@@ -1057,9 +1061,11 @@ static ssize_t dbc_bcdDevice_store(struct device *dev,
 	void __iomem *ptr;
 	u32 dev_info;
 	u16 value;
+	int ret;
 
-	if (kstrtou16(buf, 0, &value))
-		return -EINVAL;
+	ret = kstrtou16(buf, 0, &value);
+	if (ret)
+		return ret;
 
 	xhci = hcd_to_xhci(dev_get_drvdata(dev));
 	dbc = xhci->dbc;
@@ -1099,9 +1105,13 @@ static ssize_t dbc_bInterfaceProtocol_store(struct device *dev,
 	u8 value;
 	int ret;
 
-	/* bInterfaceProtocol is 8 bit, but xhci only supports values 0 and 1 */
+	/* bInterfaceProtocol is 8 bit, but... */
 	ret = kstrtou8(buf, 0, &value);
-	if (ret || value > 1)
+	if (ret)
+		return ret;
+
+	/* ...xhci only supports values 0 and 1 */
+	if (value > 1)
 		return -EINVAL;
 
 	xhci = hcd_to_xhci(dev_get_drvdata(dev));
Signature · 1 line
2.40.0.1.gaa8946217a0b
#10 lore raw

PATCH 7/10 xhci: dbc: Replace custom return value with proper Linux error code

In reply to Andy Shevchenko

Replace the custom return value with proper Linux error code.

---
 drivers/usb/host/xhci-dbgcap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci-dbgcap.c +1 -1
index 2332133c6581..617d057aa5f8 100644
@@ -593,7 +593,7 @@ static int xhci_do_dbc_start(struct xhci_dbc *dbc)
 static int xhci_do_dbc_stop(struct xhci_dbc *dbc)
 {
 	if (dbc->state == DS_DISABLED)
-		return -1;
+		return -EINVAL;
 
 	writel(0, &dbc->regs->control);
 	dbc->state = DS_DISABLED;
Signature · 1 line
2.40.0.1.gaa8946217a0b
#11 lore raw

PATCH 8/10 xhci: dbc: Use sizeof_field() where it makes sense

In reply to Andy Shevchenko

Instead of doing custom calculations, use sizeof_field() macro.

---
 drivers/usb/host/xhci-dbgcap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci-dbgcap.c +1 -1
index 617d057aa5f8..88e90c30916c 100644
@@ -374,7 +374,7 @@ static void xhci_dbc_eps_init(struct xhci_dbc *dbc)
 
 static void xhci_dbc_eps_exit(struct xhci_dbc *dbc)
 {
-	memset(dbc->eps, 0, sizeof(struct dbc_ep) * ARRAY_SIZE(dbc->eps));
+	memset(dbc->eps, 0, sizeof_field(struct xhci_dbc, eps));
 }
 
 static int dbc_erst_alloc(struct device *dev, struct xhci_ring *evt_ring,
Signature · 1 line
2.40.0.1.gaa8946217a0b
#12 lore raw

PATCH 9/10 xhci: dbc: Use sizeof(*pointer) instead of sizeof(type)

In reply to Andy Shevchenko

It is preferred to use sizeof(*pointer) instead of sizeof(type). The type of the variable can change and one needs not change the former (unlike the latter). No functional change intended.

---
 drivers/usb/host/xhci-dbgcap.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/host/xhci-dbgcap.c +3 -3
index 88e90c30916c..366ce3146a93 100644
@@ -380,7 +380,7 @@ static void xhci_dbc_eps_exit(struct xhci_dbc *dbc)
 static int dbc_erst_alloc(struct device *dev, struct xhci_ring *evt_ring,
 		    struct xhci_erst *erst, gfp_t flags)
 {
-	erst->entries = dma_alloc_coherent(dev, sizeof(struct xhci_erst_entry),
+	erst->entries = dma_alloc_coherent(dev, sizeof(*erst->entries),
 					   &erst->erst_dma_addr, flags);
 	if (!erst->entries)
 		return -ENOMEM;
@@ -394,7 +394,7 @@ static int dbc_erst_alloc(struct device *dev, struct xhci_ring *evt_ring,
 
 static void dbc_erst_free(struct device *dev, struct xhci_erst *erst)
 {
-	dma_free_coherent(dev, sizeof(struct xhci_erst_entry), erst->entries,
+	dma_free_coherent(dev, sizeof(*erst->entries), erst->entries,
 			  erst->erst_dma_addr);
 	erst->entries = NULL;
 }
@@ -494,7 +494,7 @@ static int xhci_dbc_mem_init(struct xhci_dbc *dbc, gfp_t flags)
 		goto ctx_fail;
 
 	/* Allocate the string table: */
-	dbc->string_size = sizeof(struct dbc_str_descs);
+	dbc->string_size = sizeof(*dbc->string);
 	dbc->string = dma_alloc_coherent(dev, dbc->string_size,
 					 &dbc->string_dma, flags);
 	if (!dbc->string)
Signature · 1 line
2.40.0.1.gaa8946217a0b
#13 lore raw

PATCH 10/10 xhci: dbc: Add missing headers

In reply to Andy Shevchenko

Don't inherit headers "by chances" from asm/bug.h, asm/io.h, etc... Include the needed headers explicitly.

---
 drivers/usb/host/xhci-dbgcap.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/usb/host/xhci-dbgcap.c +16 -1
index 366ce3146a93..eb2e89bf31be 100644
@@ -6,9 +6,24 @@
  *
  * Author: Lu Baolu <[email protected]>
  */
+#include <linux/device.h>
 #include <linux/dma-mapping.h>
-#include <linux/slab.h>
+#include <linux/errno.h>
+#include <linux/kstrtox.h>
+#include <linux/list.h>
 #include <linux/nls.h>
+#include <linux/pm_runtime.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/string.h>
+#include <linux/sysfs.h>
+#include <linux/types.h>
+#include <linux/workqueue.h>
+
+#include <linux/io-64-nonatomic-lo-hi.h>
+
+#include <asm/bug.h>
+#include <asm/byteorder.h>
 
 #include "xhci.h"
 #include "xhci-trace.h"
Signature · 1 line
2.40.0.1.gaa8946217a0b
#14 lore raw

Re: [PATCH v1 10/10] xhci: dbc: Add missing headers

Quoted 25 lines · Andy Shevchenko

Don't inherit headers "by chances" from asm/bug.h, asm/io.h, etc... Include the needed headers explicitly.

---
  drivers/usb/host/xhci-dbgcap.c | 17 ++++++++++++++++-
  1 file changed, 16 insertions(+), 1 deletion(-)
drivers/usb/host/xhci-dbgcap.c +6 -1
index 366ce3146a93..eb2e89bf31be 100644
@@ -6,9 +6,24 @@
   *
   * Author: Lu Baolu <[email protected]>
   */
+#include <linux/device.h>
  #include <linux/dma-mapping.h>
-#include <linux/slab.h>
+#include <linux/errno.h>
+#include <linux/kstrtox.h>
+#include <linux/list.h>
  #include <linux/nls.h>
+#include <linux/pm_runtime.h>
+#include <linux/slab.h>

drivers/usb/host/xhci-dbgcap.c line 26

Quoted 10 lines
drivers/usb/host/xhci-dbgcap.c +10 -0
+#include <linux/spinlock.h>
+#include <linux/string.h>
+#include <linux/sysfs.h>
+#include <linux/types.h>
+#include <linux/workqueue.h>
+
+#include <linux/io-64-nonatomic-lo-hi.h>
+
+#include <asm/bug.h>
+#include <asm/byteorder.h>

Checkpatch complains about this:

WARNING: Use #include <linux/bug.h> instead of <asm/bug.h>

-Mathias