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

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

 



Aruna Balakrishaiah <arunabal@...> writes:

 Hi Greg,

 I resent the patch making all the changes you mentioned.
 http://permalink.gmane.org/gmane.linux.usb.general/54968 this is the new
 patch. Sorry for the delayed response since our IMAP server was down had
issues in sending mails.

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

> @@ -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?

Since the dir path is mentioned in sysbususb, path is not expected to be
NULL.
So dint handle it. The new patch which i have sent checks for that.
>
> +
> +		 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).

Yeah agreed name looks contrary. Have taken care of it.
>
>
> +}
> +
>  /*
----------------------------------------------------------------------
> */
> 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.

I just followed how ls command works when a directory is empty it just
doesnt
print anything. But the new patch states that no USB devices found.

>
>
> +		 else
> +		 		 err = libusb_init(&ctx);
>
>
> else not really needed as there is return in the other branch of the if
> statement.
>
Agreed. Else was not needed at all. Sorry for missing it.
>
> +
>  		 if (err) {
>  		 		 fprintf(stderr, "unable to initialize libusb:
%i
> \n", err);
>  		 		 return EXIT_FAILURE;
>


Thanks,
Aruna��.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