2012-05-11 11:02:08

by Du, ChangbinX

[permalink] [raw]
Subject: [PATCH 2/3] testusb: using real device-nodes managed by udev instead of using usbfs

As the usbfs functionality have replaced by real device-nodes managed by udev whose nodes lived in /dev/bus/usb for a long time, testusb tool need update correspondingly.

Because udev path is fixed, so the "-A" option no longer need and it is removed.

Signed-off-by: Du Changbin <[email protected]>
---
tools/usb/testusb.c | 53 +++++++++------------------------------------------
1 file changed, 9 insertions(+), 44 deletions(-)

diff --git a/tools/usb/testusb.c b/tools/usb/testusb.c index 6e0f567..4fcb656 100644
--- a/tools/usb/testusb.c
+++ b/tools/usb/testusb.c
@@ -253,9 +253,6 @@ static int find_testdev(const char *name, const struct stat *sb, int flag)

if (flag != FTW_F)
return 0;
- /* ignore /proc/bus/usb/{devices,drivers} */
- if (strrchr(name, '/')[1] == 'd')
- return 0;

fd = fopen(name, "rb");
if (!fd) {
@@ -354,31 +351,6 @@ restart:
return arg;
}

-static const char *usbfs_dir_find(void) -{
- static char usbfs_path_0[] = "/dev/usb/devices";
- static char usbfs_path_1[] = "/proc/bus/usb/devices";
-
- static char *const usbfs_paths[] = {
- usbfs_path_0, usbfs_path_1
- };
-
- static char *const *
- end = usbfs_paths + sizeof usbfs_paths / sizeof *usbfs_paths;
-
- char *const *it = usbfs_paths;
- do {
- int fd = open(*it, O_RDONLY);
- close(fd);
- if (fd >= 0) {
- strrchr(*it, '/')[0] = '\0';
- return *it;
- }
- } while (++it != end);
-
- return NULL;
-}
-
static int parse_num(unsigned *num, const char *str) {
unsigned long val;
@@ -398,7 +370,7 @@ int main (int argc, char **argv)
int c;
struct testdev *entry;
char *device;
- const char *usbfs_dir = NULL;
+ const char *usb_dir = "/dev/bus/usb";
int all = 0, forever = 0, not = 0;
int test = -1 /* all */;
struct usbtest_param param;
@@ -420,14 +392,11 @@ int main (int argc, char **argv)
/* for easy use when hotplugging */
device = getenv ("DEVICE");

- while ((c = getopt (argc, argv, "D:aA:c:g:hns:t:v:")) != EOF)
+ while ((c = getopt (argc, argv, "D:ac:g:lhns:t:v:")) != EOF)
switch (c) {
case 'D': /* device, if only one */
device = optarg;
continue;
- case 'A': /* use all devices with specified usbfs dir */
- usbfs_dir = optarg;
- /* FALL THROUGH */
case 'a': /* use all devices */
device = NULL;
all = 1;
@@ -463,7 +432,7 @@ int main (int argc, char **argv)
case 'h':
default:
usage:
- fprintf (stderr, "usage: %s [-n] [-D dev | -a | -A usbfs-dir]\n"
+ fprintf (stderr, "usage: %s [-n] [-D dev | -a]\n"
"\t[-c iterations] [-t testnum]\n"
"\t[-s packetsize] [-g sglen] [-v vary]\n",
argv [0]);
@@ -473,22 +442,18 @@ usage:
goto usage;
if (!all && !device) {
fprintf (stderr, "must specify '-a' or '-D dev', "
- "or DEVICE=/proc/bus/usb/BBB/DDD in env\n");
+ "or DEVICE=%s/BBB/DDD in env\n", usb_dir);
goto usage;
}

- /* Find usbfs mount point */
- if (!usbfs_dir) {
- usbfs_dir = usbfs_dir_find();
- if (!usbfs_dir) {
- fputs ("usbfs files are missing\n", stderr);
- return -1;
- }
+ if (access(usb_dir,F_OK) != 0) {
+ fprintf(stderr, "can not find path %s\n", usb_dir);
+ return -1;
}

/* collect and list the test devices */
- if (ftw (usbfs_dir, find_testdev, 3) != 0) {
- fputs ("ftw failed; is usbfs missing?\n", stderr);
+ if (ftw (usb_dir, find_testdev, 3) != 0) {
+ fputs ("ftw failed.\n", stderr);
return -1;
}

--
1.7.9.5


2012-05-11 22:09:26

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 2/3] testusb: using real device-nodes managed by udev instead of using usbfs

On Fri, May 11, 2012 at 11:02:01AM +0000, Du, ChangbinX wrote:
> As the usbfs functionality have replaced by real device-nodes managed by udev whose nodes lived in /dev/bus/usb for a long time, testusb tool need update correspondingly.

Why? Is this causing problems as it is today?

> Because udev path is fixed, so the "-A" option no longer need and it is removed.

Did you just break scripts that was using that option? That's not nice,
and not acceptable.

greg k-h

2012-05-14 03:31:20

by Du, ChangbinX

[permalink] [raw]
Subject: RE: [PATCH 2/3] testusb: using real device-nodes managed by udev instead of using usbfs

I am sorry I haven't consider of that. I just want testusb tool can work with default option since path /dev/bus/usb exists on most computer, not /proc/bus/usb.
So, if I just add /dev/bus/usb to the default search path, is it ok? Thanks.

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Saturday, May 12, 2012 6:09 AM
To: Du, ChangbinX
Cc: [email protected]; Fleming, Matt; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 2/3] testusb: using real device-nodes managed by udev instead of using usbfs

On Fri, May 11, 2012 at 11:02:01AM +0000, Du, ChangbinX wrote:
> As the usbfs functionality have replaced by real device-nodes managed by udev whose nodes lived in /dev/bus/usb for a long time, testusb tool need update correspondingly.

Why? Is this causing problems as it is today?

> Because udev path is fixed, so the "-A" option no longer need and it is removed.

Did you just break scripts that was using that option? That's not nice, and not acceptable.

greg k-h

2012-05-14 04:17:45

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 2/3] testusb: using real device-nodes managed by udev instead of using usbfs


A: No.
Q: Should I include quotations after my reply?

http://daringfireball.net/2007/07/on_top

On Mon, May 14, 2012 at 03:31:14AM +0000, Du, ChangbinX wrote:
> I am sorry I haven't consider of that. I just want testusb tool can
> work with default option since path /dev/bus/usb exists on most
> computer, not /proc/bus/usb.
> So, if I just add /dev/bus/usb to the default search path, is it ok? Thanks.

Yes, that would make more sense to do.

greg k-h