Re: fix for lsusb: unable to initialize libusb: -99

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Michal,

Thanks for reviewing the patch . Have taken care of the things you have
mentioned and resent the patch.

Thanks,
Aruna H B
IBM Linux technology Centre.
Bangalore.

@@ -3920,6 +3922,25 @@ static int treedump(void)
 		 return 0;
 }
+static int check_for_usbdevice(void)
+{
+		 struct dirent *d;
+		 int n = 0;
+		 DIR *dir = opendir(sysbususb);


You are aware dir can be NULL on error, right?  Shouldn't that be handled?


+
+		 while ((d = readdir(dir)) != NULL) {
+		 		 if (++n > 2)
+		 		 		 break;
+		 }
+
+		 closedir(dir);
+
+		 if (n <= 2)
+		 		 return 1;
+		 else
+		 		 return 0;


So if the directory is empty (ie. has only “.” and “..”) the function
returns
true value?  This feels contrary to the name of the function. Also, how
about just:

		 return n > 2;

(not that this has reversed logic).


+}
+
 /* ----------------------------------------------------------------------
*/
int main(int argc, char *argv[])
@@ -4027,7 +4048,11 @@ int main(int argc, char *argv[])
 		 		 		 		 strerror(err));
 		 status = 0;
-		 err = libusb_init(&ctx);
+		 if (check_for_usbdevice())
+		 		 return 0;


So if there are no USB devices you return with zero exit code and no error
message?  That's not very friendly.


+		 else
+		 		 err = libusb_init(&ctx);


else not really needed as there is return in the other branch of the if
statement.


+
 		 if (err) {
 		 		 fprintf(stderr, "unable to initialize libusb: %i
\n", err);
 		 		 return EXIT_FAILURE;
��.n��������+%������w��{.n�����{���)��jg��������ݢj����G�������j:+v���w�m������w�������h�����٥



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux