2021-06-15 06:41:23

by Zou Wei

[permalink] [raw]
Subject: [PATCH -next] usbip: tools: Convert list_for_each to entry variant

convert list_for_each() to list_for_each_entry() where
applicable.

Reported-by: Hulk Robot <[email protected]>
Signed-off-by: Zou Wei <[email protected]>
---
tools/usb/usbip/libsrc/usbip_host_common.c | 4 +---
tools/usb/usbip/src/usbipd.c | 8 ++------
2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/tools/usb/usbip/libsrc/usbip_host_common.c b/tools/usb/usbip/libsrc/usbip_host_common.c
index ca78aa3..80f16f0 100644
--- a/tools/usb/usbip/libsrc/usbip_host_common.c
+++ b/tools/usb/usbip/libsrc/usbip_host_common.c
@@ -267,12 +267,10 @@ int usbip_export_device(struct usbip_exported_device *edev, int sockfd)
struct usbip_exported_device *usbip_generic_get_device(
struct usbip_host_driver *hdriver, int num)
{
- struct list_head *i;
struct usbip_exported_device *edev;
int cnt = 0;

- list_for_each(i, &hdriver->edev_list) {
- edev = list_entry(i, struct usbip_exported_device, node);
+ list_for_each_entry(edev, &hdriver->edev_list, node) {
if (num == cnt)
return edev;
cnt++;
diff --git a/tools/usb/usbip/src/usbipd.c b/tools/usb/usbip/src/usbipd.c
index 48398a7..438346e 100644
--- a/tools/usb/usbip/src/usbipd.c
+++ b/tools/usb/usbip/src/usbipd.c
@@ -93,7 +93,6 @@ static int recv_request_import(int sockfd)
struct op_import_request req;
struct usbip_exported_device *edev;
struct usbip_usb_device pdu_udev;
- struct list_head *i;
int found = 0;
int status = ST_OK;
int rc;
@@ -107,8 +106,7 @@ static int recv_request_import(int sockfd)
}
PACK_OP_IMPORT_REQUEST(0, &req);

- list_for_each(i, &driver->edev_list) {
- edev = list_entry(i, struct usbip_exported_device, node);
+ list_for_each_entry(edev, &driver->edev_list, node) {
if (!strncmp(req.busid, edev->udev.busid, SYSFS_BUS_ID_SIZE)) {
info("found requested device: %s", req.busid);
found = 1;
@@ -160,7 +158,6 @@ static int send_reply_devlist(int connfd)
struct usbip_usb_device pdu_udev;
struct usbip_usb_interface pdu_uinf;
struct op_devlist_reply reply;
- struct list_head *j;
int rc, i;

/*
@@ -174,8 +171,7 @@ static int send_reply_devlist(int connfd)

reply.ndev = 0;
/* number of exported devices */
- list_for_each(j, &driver->edev_list) {
- edev = list_entry(j, struct usbip_exported_device, node);
+ list_for_each_entry(edev, &driver->edev_list, node) {
if (edev->status != SDEV_ST_USED)
reply.ndev += 1;
}
--
2.6.2


2021-06-15 17:50:21

by Shuah Khan

[permalink] [raw]
Subject: Re: [PATCH -next] usbip: tools: Convert list_for_each to entry variant

On 6/15/21 12:58 AM, Zou Wei wrote:
> convert list_for_each() to list_for_each_entry() where
> applicable.
> > Reported-by: Hulk Robot <[email protected]>

What is the report? Please include the reports.

> Signed-off-by: Zou Wei <[email protected]>
> ---
> tools/usb/usbip/libsrc/usbip_host_common.c | 4 +---
> tools/usb/usbip/src/usbipd.c | 8 ++------
> 2 files changed, 3 insertions(+), 9 deletions(-)
>

Please explain why this change is necessary. Is it a good
idea to explain what happens if you don't make this change?

thanks,
-- Shuah