public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 01/10] xhci: dbc: Drop duplicate checks for dma_free_coherent()
@ 2023-10-02 16:16 Andy Shevchenko
  2023-10-02 16:16 ` [PATCH v1 02/10] xhci: dbc: Convert to use sysfs_streq() Andy Shevchenko
                   ` (8 more replies)
  0 siblings, 9 replies; 15+ messages in thread
From: Andy Shevchenko @ 2023-10-02 16:16 UTC (permalink / raw)
  To: Andy Shevchenko, Mathias Nyman, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman

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

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index b40d9238d447..9e9ce3711813 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -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;
-- 
2.40.0.1.gaa8946217a0b


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v1 02/10] xhci: dbc: Convert to use sysfs_streq()
  2023-10-02 16:16 [PATCH v1 01/10] xhci: dbc: Drop duplicate checks for dma_free_coherent() Andy Shevchenko
@ 2023-10-02 16:16 ` Andy Shevchenko
  2023-10-02 16:16 ` [PATCH v1 03/10] xhci: dbc: Use sysfs_emit() to instead of scnprintf() Andy Shevchenko
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2023-10-02 16:16 UTC (permalink / raw)
  To: Andy Shevchenko, Mathias Nyman, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman

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

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 9e9ce3711813..f505b79afe53 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -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;
-- 
2.40.0.1.gaa8946217a0b


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v1 03/10] xhci: dbc: Use sysfs_emit() to instead of scnprintf()
  2023-10-02 16:16 [PATCH v1 01/10] xhci: dbc: Drop duplicate checks for dma_free_coherent() Andy Shevchenko
  2023-10-02 16:16 ` [PATCH v1 02/10] xhci: dbc: Convert to use sysfs_streq() Andy Shevchenko
@ 2023-10-02 16:16 ` Andy Shevchenko
  2023-10-02 18:03   ` kernel test robot
  2023-10-02 16:16 ` [PATCH v1 04/10] xhci: dbc: Use ATTRIBUTE_GROUPS() Andy Shevchenko
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 15+ messages in thread
From: Andy Shevchenko @ 2023-10-02 16:16 UTC (permalink / raw)
  To: Andy Shevchenko, Mathias Nyman, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman

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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 43 +++++++++++++---------------------
 drivers/usb/host/xhci-dbgcap.h |  1 +
 2 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index f505b79afe53..92869c67a430 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -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,
diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h
index 51a7ab3ba0ca..e39e3ae1677a 100644
--- a/drivers/usb/host/xhci-dbgcap.h
+++ b/drivers/usb/host/xhci-dbgcap.h
@@ -82,6 +82,7 @@ enum dbc_state {
 	DS_CONNECTED,
 	DS_CONFIGURED,
 	DS_STALLED,
+	DS_MAX
 };
 
 struct dbc_ep {
-- 
2.40.0.1.gaa8946217a0b


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v1 04/10] xhci: dbc: Use ATTRIBUTE_GROUPS()
  2023-10-02 16:16 [PATCH v1 01/10] xhci: dbc: Drop duplicate checks for dma_free_coherent() Andy Shevchenko
  2023-10-02 16:16 ` [PATCH v1 02/10] xhci: dbc: Convert to use sysfs_streq() Andy Shevchenko
  2023-10-02 16:16 ` [PATCH v1 03/10] xhci: dbc: Use sysfs_emit() to instead of scnprintf() Andy Shevchenko
@ 2023-10-02 16:16 ` Andy Shevchenko
  2023-10-11 14:18   ` Mathias Nyman
  2023-10-02 16:16 ` [PATCH v1 05/10] xhci: dbc: Check for errors first in xhci_dbc_stop() Andy Shevchenko
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 15+ messages in thread
From: Andy Shevchenko @ 2023-10-02 16:16 UTC (permalink / raw)
  To: Andy Shevchenko, Mathias Nyman, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman

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

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 92869c67a430..3c90410e9cde 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -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);
 }
-- 
2.40.0.1.gaa8946217a0b


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v1 05/10] xhci: dbc: Check for errors first in xhci_dbc_stop()
  2023-10-02 16:16 [PATCH v1 01/10] xhci: dbc: Drop duplicate checks for dma_free_coherent() Andy Shevchenko
                   ` (2 preceding siblings ...)
  2023-10-02 16:16 ` [PATCH v1 04/10] xhci: dbc: Use ATTRIBUTE_GROUPS() Andy Shevchenko
@ 2023-10-02 16:16 ` Andy Shevchenko
  2023-10-02 16:16 ` [PATCH v1 06/10] xhci: dbc: Don't shadow error codes in store() functions Andy Shevchenko
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2023-10-02 16:16 UTC (permalink / raw)
  To: Andy Shevchenko, Mathias Nyman, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman

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

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 3c90410e9cde..d110eb5f1625 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -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
-- 
2.40.0.1.gaa8946217a0b


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v1 06/10] xhci: dbc: Don't shadow error codes in store() functions
  2023-10-02 16:16 [PATCH v1 01/10] xhci: dbc: Drop duplicate checks for dma_free_coherent() Andy Shevchenko
                   ` (3 preceding siblings ...)
  2023-10-02 16:16 ` [PATCH v1 05/10] xhci: dbc: Check for errors first in xhci_dbc_stop() Andy Shevchenko
@ 2023-10-02 16:16 ` Andy Shevchenko
  2023-10-02 16:16 ` [PATCH v1 07/10] xhci: dbc: Replace custom return value with proper Linux error code Andy Shevchenko
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2023-10-02 16:16 UTC (permalink / raw)
  To: Andy Shevchenko, Mathias Nyman, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman

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

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index d110eb5f1625..2332133c6581 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -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));
-- 
2.40.0.1.gaa8946217a0b


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v1 07/10] xhci: dbc: Replace custom return value with proper Linux error code
  2023-10-02 16:16 [PATCH v1 01/10] xhci: dbc: Drop duplicate checks for dma_free_coherent() Andy Shevchenko
                   ` (4 preceding siblings ...)
  2023-10-02 16:16 ` [PATCH v1 06/10] xhci: dbc: Don't shadow error codes in store() functions Andy Shevchenko
@ 2023-10-02 16:16 ` Andy Shevchenko
  2023-10-02 16:16 ` [PATCH v1 08/10] xhci: dbc: Use sizeof_field() where it makes sense Andy Shevchenko
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2023-10-02 16:16 UTC (permalink / raw)
  To: Andy Shevchenko, Mathias Nyman, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman

Replace the custom return value with proper Linux error code.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 2332133c6581..617d057aa5f8 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -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;
-- 
2.40.0.1.gaa8946217a0b


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v1 08/10] xhci: dbc: Use sizeof_field() where it makes sense
  2023-10-02 16:16 [PATCH v1 01/10] xhci: dbc: Drop duplicate checks for dma_free_coherent() Andy Shevchenko
                   ` (5 preceding siblings ...)
  2023-10-02 16:16 ` [PATCH v1 07/10] xhci: dbc: Replace custom return value with proper Linux error code Andy Shevchenko
@ 2023-10-02 16:16 ` Andy Shevchenko
  2023-10-02 16:16 ` [PATCH v1 09/10] xhci: dbc: Use sizeof(*pointer) instead of sizeof(type) Andy Shevchenko
  2023-10-02 16:16 ` [PATCH v1 10/10] xhci: dbc: Add missing headers Andy Shevchenko
  8 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2023-10-02 16:16 UTC (permalink / raw)
  To: Andy Shevchenko, Mathias Nyman, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman

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

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 617d057aa5f8..88e90c30916c 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -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,
-- 
2.40.0.1.gaa8946217a0b


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v1 09/10] xhci: dbc: Use sizeof(*pointer) instead of sizeof(type)
  2023-10-02 16:16 [PATCH v1 01/10] xhci: dbc: Drop duplicate checks for dma_free_coherent() Andy Shevchenko
                   ` (6 preceding siblings ...)
  2023-10-02 16:16 ` [PATCH v1 08/10] xhci: dbc: Use sizeof_field() where it makes sense Andy Shevchenko
@ 2023-10-02 16:16 ` Andy Shevchenko
  2023-10-02 16:16 ` [PATCH v1 10/10] xhci: dbc: Add missing headers Andy Shevchenko
  8 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2023-10-02 16:16 UTC (permalink / raw)
  To: Andy Shevchenko, Mathias Nyman, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman

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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 88e90c30916c..366ce3146a93 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -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)
-- 
2.40.0.1.gaa8946217a0b


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v1 10/10] xhci: dbc: Add missing headers
  2023-10-02 16:16 [PATCH v1 01/10] xhci: dbc: Drop duplicate checks for dma_free_coherent() Andy Shevchenko
                   ` (7 preceding siblings ...)
  2023-10-02 16:16 ` [PATCH v1 09/10] xhci: dbc: Use sizeof(*pointer) instead of sizeof(type) Andy Shevchenko
@ 2023-10-02 16:16 ` Andy Shevchenko
  2023-10-11 14:20   ` Mathias Nyman
  8 siblings, 1 reply; 15+ messages in thread
From: Andy Shevchenko @ 2023-10-02 16:16 UTC (permalink / raw)
  To: Andy Shevchenko, Mathias Nyman, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman

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

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 366ce3146a93..eb2e89bf31be 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -6,9 +6,24 @@
  *
  * Author: Lu Baolu <baolu.lu@linux.intel.com>
  */
+#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"
-- 
2.40.0.1.gaa8946217a0b


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH v1 03/10] xhci: dbc: Use sysfs_emit() to instead of scnprintf()
  2023-10-02 16:16 ` [PATCH v1 03/10] xhci: dbc: Use sysfs_emit() to instead of scnprintf() Andy Shevchenko
@ 2023-10-02 18:03   ` kernel test robot
  2023-10-03  8:50     ` Andy Shevchenko
  0 siblings, 1 reply; 15+ messages in thread
From: kernel test robot @ 2023-10-02 18:03 UTC (permalink / raw)
  To: Andy Shevchenko, Mathias Nyman, linux-usb, linux-kernel
  Cc: oe-kbuild-all, Greg Kroah-Hartman

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/202310030150.M1SfrYmG-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231003/202310030150.M1SfrYmG-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202310030150.M1SfrYmG-lkp@intel.com/

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  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v1 03/10] xhci: dbc: Use sysfs_emit() to instead of scnprintf()
  2023-10-02 18:03   ` kernel test robot
@ 2023-10-03  8:50     ` Andy Shevchenko
  2023-10-03 12:30       ` Mathias Nyman
  0 siblings, 1 reply; 15+ messages in thread
From: Andy Shevchenko @ 2023-10-03  8:50 UTC (permalink / raw)
  To: kernel test robot
  Cc: Mathias Nyman, linux-usb, linux-kernel, oe-kbuild-all,
	Greg Kroah-Hartman

On Tue, Oct 03, 2023 at 02:03:53AM +0800, kernel test robot wrote:


> 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;
>          |                                  ^

Indeed, forgot to remove it...

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

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v1 03/10] xhci: dbc: Use sysfs_emit() to instead of scnprintf()
  2023-10-03  8:50     ` Andy Shevchenko
@ 2023-10-03 12:30       ` Mathias Nyman
  0 siblings, 0 replies; 15+ messages in thread
From: Mathias Nyman @ 2023-10-03 12:30 UTC (permalink / raw)
  To: Andy Shevchenko, kernel test robot
  Cc: linux-usb, linux-kernel, oe-kbuild-all, Greg Kroah-Hartman

On 3.10.2023 11.50, Andy Shevchenko wrote:
> On Tue, Oct 03, 2023 at 02:03:53AM +0800, kernel test robot wrote:
> 
> 
>> 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;
>>           |                                  ^
> 
> 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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v1 04/10] xhci: dbc: Use ATTRIBUTE_GROUPS()
  2023-10-02 16:16 ` [PATCH v1 04/10] xhci: dbc: Use ATTRIBUTE_GROUPS() Andy Shevchenko
@ 2023-10-11 14:18   ` Mathias Nyman
  0 siblings, 0 replies; 15+ messages in thread
From: Mathias Nyman @ 2023-10-11 14:18 UTC (permalink / raw)
  To: Andy Shevchenko, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman

On 2.10.2023 19.16, Andy Shevchenko wrote:
> Embrace ATTRIBUTE_GROUPS() to avoid boiler plate code.
> This should not introduce any functional changes.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>   drivers/usb/host/xhci-dbgcap.c | 11 ++++-------
>   1 file changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
> index 92869c67a430..3c90410e9cde 100644
> --- a/drivers/usb/host/xhci-dbgcap.c
> +++ b/drivers/usb/host/xhci-dbgcap.c
> @@ -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)  
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



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v1 10/10] xhci: dbc: Add missing headers
  2023-10-02 16:16 ` [PATCH v1 10/10] xhci: dbc: Add missing headers Andy Shevchenko
@ 2023-10-11 14:20   ` Mathias Nyman
  0 siblings, 0 replies; 15+ messages in thread
From: Mathias Nyman @ 2023-10-11 14:20 UTC (permalink / raw)
  To: Andy Shevchenko, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman

On 2.10.2023 19.16, Andy Shevchenko wrote:
> Don't inherit headers "by chances" from asm/bug.h, asm/io.h,
> etc... Include the needed headers explicitly.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>   drivers/usb/host/xhci-dbgcap.c | 17 ++++++++++++++++-
>   1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
> index 366ce3146a93..eb2e89bf31be 100644
> --- a/drivers/usb/host/xhci-dbgcap.c
> +++ b/drivers/usb/host/xhci-dbgcap.c
> @@ -6,9 +6,24 @@
>    *
>    * Author: Lu Baolu <baolu.lu@linux.intel.com>
>    */
> +#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>

Checkpatch complains about this:

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

-Mathias

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-10-11 14:19 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-02 16:16 [PATCH v1 01/10] xhci: dbc: Drop duplicate checks for dma_free_coherent() Andy Shevchenko
2023-10-02 16:16 ` [PATCH v1 02/10] xhci: dbc: Convert to use sysfs_streq() Andy Shevchenko
2023-10-02 16:16 ` [PATCH v1 03/10] xhci: dbc: Use sysfs_emit() to instead of scnprintf() Andy Shevchenko
2023-10-02 18:03   ` kernel test robot
2023-10-03  8:50     ` Andy Shevchenko
2023-10-03 12:30       ` Mathias Nyman
2023-10-02 16:16 ` [PATCH v1 04/10] xhci: dbc: Use ATTRIBUTE_GROUPS() Andy Shevchenko
2023-10-11 14:18   ` Mathias Nyman
2023-10-02 16:16 ` [PATCH v1 05/10] xhci: dbc: Check for errors first in xhci_dbc_stop() Andy Shevchenko
2023-10-02 16:16 ` [PATCH v1 06/10] xhci: dbc: Don't shadow error codes in store() functions Andy Shevchenko
2023-10-02 16:16 ` [PATCH v1 07/10] xhci: dbc: Replace custom return value with proper Linux error code Andy Shevchenko
2023-10-02 16:16 ` [PATCH v1 08/10] xhci: dbc: Use sizeof_field() where it makes sense Andy Shevchenko
2023-10-02 16:16 ` [PATCH v1 09/10] xhci: dbc: Use sizeof(*pointer) instead of sizeof(type) Andy Shevchenko
2023-10-02 16:16 ` [PATCH v1 10/10] xhci: dbc: Add missing headers Andy Shevchenko
2023-10-11 14:20   ` Mathias Nyman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox