* [PATCH v2 00/10] xhci: dbc: Update driver to use modern APIs
@ 2023-10-16 13:09 Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 01/10] xhci: dbc: Drop duplicate checks for dma_free_coherent() Andy Shevchenko
` (9 more replies)
0 siblings, 10 replies; 13+ messages in thread
From: Andy Shevchenko @ 2023-10-16 13:09 UTC (permalink / raw)
To: Andy Shevchenko, Mathias Nyman, linux-usb, linux-kernel
Cc: Mathias Nyman, Greg Kroah-Hartman
Update driver to use some of modern APIs. It's not a full clean up
series, just a set of ad-hoc changes.
In v2:
- fixed mistakes pointed by Mathias and LKP
- sent with a cover letter
Andy Shevchenko (10):
xhci: dbc: Drop duplicate checks for dma_free_coherent()
xhci: dbc: Convert to use sysfs_streq()
xhci: dbc: Use sysfs_emit() to instead of scnprintf()
xhci: dbc: Use ATTRIBUTE_GROUPS()
xhci: dbc: Check for errors first in xhci_dbc_stop()
xhci: dbc: Don't shadow error codes in store() functions
xhci: dbc: Replace custom return value with proper Linux error code
xhci: dbc: Use sizeof_field() where it makes sense
xhci: dbc: Use sizeof(*pointer) instead of sizeof(type)
xhci: dbc: Add missing headers
drivers/usb/host/xhci-dbgcap.c | 132 +++++++++++++++++----------------
drivers/usb/host/xhci-dbgcap.h | 1 +
2 files changed, 70 insertions(+), 63 deletions(-)
--
2.40.0.1.gaa8946217a0b
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 01/10] xhci: dbc: Drop duplicate checks for dma_free_coherent()
2023-10-16 13:09 [PATCH v2 00/10] xhci: dbc: Update driver to use modern APIs Andy Shevchenko
@ 2023-10-16 13:09 ` Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 02/10] xhci: dbc: Convert to use sysfs_streq() Andy Shevchenko
` (8 subsequent siblings)
9 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2023-10-16 13:09 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] 13+ messages in thread
* [PATCH v2 02/10] xhci: dbc: Convert to use sysfs_streq()
2023-10-16 13:09 [PATCH v2 00/10] xhci: dbc: Update driver to use modern APIs Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 01/10] xhci: dbc: Drop duplicate checks for dma_free_coherent() Andy Shevchenko
@ 2023-10-16 13:09 ` Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 03/10] xhci: dbc: Use sysfs_emit() to instead of scnprintf() Andy Shevchenko
` (7 subsequent siblings)
9 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2023-10-16 13:09 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] 13+ messages in thread
* [PATCH v2 03/10] xhci: dbc: Use sysfs_emit() to instead of scnprintf()
2023-10-16 13:09 [PATCH v2 00/10] xhci: dbc: Update driver to use modern APIs Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 01/10] xhci: dbc: Drop duplicate checks for dma_free_coherent() Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 02/10] xhci: dbc: Convert to use sysfs_streq() Andy Shevchenko
@ 2023-10-16 13:09 ` Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 04/10] xhci: dbc: Use ATTRIBUTE_GROUPS() Andy Shevchenko
` (6 subsequent siblings)
9 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2023-10-16 13:09 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 | 44 +++++++++++++---------------------
drivers/usb/host/xhci-dbgcap.h | 1 +
2 files changed, 17 insertions(+), 28 deletions(-)
diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index f505b79afe53..df14e336370d 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -910,41 +910,29 @@ 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)
{
- const char *p;
struct xhci_dbc *dbc;
struct xhci_hcd *xhci;
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 +965,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 +1005,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 +1044,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 +1084,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] 13+ messages in thread
* [PATCH v2 04/10] xhci: dbc: Use ATTRIBUTE_GROUPS()
2023-10-16 13:09 [PATCH v2 00/10] xhci: dbc: Update driver to use modern APIs Andy Shevchenko
` (2 preceding siblings ...)
2023-10-16 13:09 ` [PATCH v2 03/10] xhci: dbc: Use sysfs_emit() to instead of scnprintf() Andy Shevchenko
@ 2023-10-16 13:09 ` Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 05/10] xhci: dbc: Check for errors first in xhci_dbc_stop() Andy Shevchenko
` (5 subsequent siblings)
9 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2023-10-16 13:09 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 df14e336370d..660e3ee31dc6 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -1123,7 +1123,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,
@@ -1131,10 +1131,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)
@@ -1160,7 +1157,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;
@@ -1179,7 +1176,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] 13+ messages in thread
* [PATCH v2 05/10] xhci: dbc: Check for errors first in xhci_dbc_stop()
2023-10-16 13:09 [PATCH v2 00/10] xhci: dbc: Update driver to use modern APIs Andy Shevchenko
` (3 preceding siblings ...)
2023-10-16 13:09 ` [PATCH v2 04/10] xhci: dbc: Use ATTRIBUTE_GROUPS() Andy Shevchenko
@ 2023-10-16 13:09 ` Andy Shevchenko
2023-10-16 16:55 ` Sergei Shtylyov
2023-10-16 13:09 ` [PATCH v2 06/10] xhci: dbc: Don't shadow error codes in store() functions Andy Shevchenko
` (4 subsequent siblings)
9 siblings, 1 reply; 13+ messages in thread
From: Andy Shevchenko @ 2023-10-16 13:09 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 660e3ee31dc6..6b9f4b839270 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] 13+ messages in thread
* [PATCH v2 06/10] xhci: dbc: Don't shadow error codes in store() functions
2023-10-16 13:09 [PATCH v2 00/10] xhci: dbc: Update driver to use modern APIs Andy Shevchenko
` (4 preceding siblings ...)
2023-10-16 13:09 ` [PATCH v2 05/10] xhci: dbc: Check for errors first in xhci_dbc_stop() Andy Shevchenko
@ 2023-10-16 13:09 ` Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 07/10] xhci: dbc: Replace custom return value with proper Linux error code Andy Shevchenko
` (3 subsequent siblings)
9 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2023-10-16 13:09 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 6b9f4b839270..c211c69e8041 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -977,9 +977,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;
@@ -1017,9 +1019,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;
@@ -1056,9 +1060,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;
@@ -1098,9 +1104,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] 13+ messages in thread
* [PATCH v2 07/10] xhci: dbc: Replace custom return value with proper Linux error code
2023-10-16 13:09 [PATCH v2 00/10] xhci: dbc: Update driver to use modern APIs Andy Shevchenko
` (5 preceding siblings ...)
2023-10-16 13:09 ` [PATCH v2 06/10] xhci: dbc: Don't shadow error codes in store() functions Andy Shevchenko
@ 2023-10-16 13:09 ` Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 08/10] xhci: dbc: Use sizeof_field() where it makes sense Andy Shevchenko
` (2 subsequent siblings)
9 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2023-10-16 13:09 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 c211c69e8041..779a564ad698 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] 13+ messages in thread
* [PATCH v2 08/10] xhci: dbc: Use sizeof_field() where it makes sense
2023-10-16 13:09 [PATCH v2 00/10] xhci: dbc: Update driver to use modern APIs Andy Shevchenko
` (6 preceding siblings ...)
2023-10-16 13:09 ` [PATCH v2 07/10] xhci: dbc: Replace custom return value with proper Linux error code Andy Shevchenko
@ 2023-10-16 13:09 ` Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 09/10] xhci: dbc: Use sizeof(*pointer) instead of sizeof(type) Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 10/10] xhci: dbc: Add missing headers Andy Shevchenko
9 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2023-10-16 13:09 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 779a564ad698..0c9fd61e9c5b 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] 13+ messages in thread
* [PATCH v2 09/10] xhci: dbc: Use sizeof(*pointer) instead of sizeof(type)
2023-10-16 13:09 [PATCH v2 00/10] xhci: dbc: Update driver to use modern APIs Andy Shevchenko
` (7 preceding siblings ...)
2023-10-16 13:09 ` [PATCH v2 08/10] xhci: dbc: Use sizeof_field() where it makes sense Andy Shevchenko
@ 2023-10-16 13:09 ` Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 10/10] xhci: dbc: Add missing headers Andy Shevchenko
9 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2023-10-16 13:09 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 0c9fd61e9c5b..73494d55b0be 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] 13+ messages in thread
* [PATCH v2 10/10] xhci: dbc: Add missing headers
2023-10-16 13:09 [PATCH v2 00/10] xhci: dbc: Update driver to use modern APIs Andy Shevchenko
` (8 preceding siblings ...)
2023-10-16 13:09 ` [PATCH v2 09/10] xhci: dbc: Use sizeof(*pointer) instead of sizeof(type) Andy Shevchenko
@ 2023-10-16 13:09 ` Andy Shevchenko
9 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2023-10-16 13:09 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 73494d55b0be..d82935d31126 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/bug.h>
+#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/byteorder.h>
#include "xhci.h"
#include "xhci-trace.h"
--
2.40.0.1.gaa8946217a0b
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2 05/10] xhci: dbc: Check for errors first in xhci_dbc_stop()
2023-10-16 13:09 ` [PATCH v2 05/10] xhci: dbc: Check for errors first in xhci_dbc_stop() Andy Shevchenko
@ 2023-10-16 16:55 ` Sergei Shtylyov
2023-10-23 14:06 ` Mathias Nyman
0 siblings, 1 reply; 13+ messages in thread
From: Sergei Shtylyov @ 2023-10-16 16:55 UTC (permalink / raw)
To: Andy Shevchenko, Mathias Nyman, linux-usb, linux-kernel
Cc: Mathias Nyman, Greg Kroah-Hartman
On 10/16/23 4:09 PM, Andy Shevchenko wrote:
> The usual patter is to check for errors and then continue if none.
Pattern. :-)
> Apply that pattern to xhci_dbc_stop() code.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
[...]
MBR, Sergey
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 05/10] xhci: dbc: Check for errors first in xhci_dbc_stop()
2023-10-16 16:55 ` Sergei Shtylyov
@ 2023-10-23 14:06 ` Mathias Nyman
0 siblings, 0 replies; 13+ messages in thread
From: Mathias Nyman @ 2023-10-23 14:06 UTC (permalink / raw)
To: Sergei Shtylyov, Andy Shevchenko, linux-usb, linux-kernel
Cc: Mathias Nyman, Greg Kroah-Hartman
On 16.10.2023 19.55, Sergei Shtylyov wrote:
> On 10/16/23 4:09 PM, Andy Shevchenko wrote:
>
>> The usual patter is to check for errors and then continue if none.
>
> Pattern. :-)
>
I'll fix it while applying
-Mathias
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2023-10-23 14:04 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-16 13:09 [PATCH v2 00/10] xhci: dbc: Update driver to use modern APIs Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 01/10] xhci: dbc: Drop duplicate checks for dma_free_coherent() Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 02/10] xhci: dbc: Convert to use sysfs_streq() Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 03/10] xhci: dbc: Use sysfs_emit() to instead of scnprintf() Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 04/10] xhci: dbc: Use ATTRIBUTE_GROUPS() Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 05/10] xhci: dbc: Check for errors first in xhci_dbc_stop() Andy Shevchenko
2023-10-16 16:55 ` Sergei Shtylyov
2023-10-23 14:06 ` Mathias Nyman
2023-10-16 13:09 ` [PATCH v2 06/10] xhci: dbc: Don't shadow error codes in store() functions Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 07/10] xhci: dbc: Replace custom return value with proper Linux error code Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 08/10] xhci: dbc: Use sizeof_field() where it makes sense Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 09/10] xhci: dbc: Use sizeof(*pointer) instead of sizeof(type) Andy Shevchenko
2023-10-16 13:09 ` [PATCH v2 10/10] xhci: dbc: Add missing headers Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).