2023-10-02 18:44:44

by Andy Shevchenko

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

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 <[email protected]>
---
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


2023-10-02 22:16:14

by kernel test robot

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

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

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

2023-10-03 08:50:28

by Andy Shevchenko

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

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


2023-10-03 12:29:21

by Mathias Nyman

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

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