Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 2551 #3956

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion drivers/usb/core/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,13 @@ EXPORT_SYMBOL_GPL(usb_find_alt_setting);
struct usb_interface *usb_ifnum_to_if(const struct usb_device *dev,
unsigned ifnum)
{
struct usb_host_config *config = dev->actconfig;
struct usb_host_config *config = NULL;
int i;

if (!dev)
return NULL;
Comment on lines +279 to +280

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really no linux hacker, but wouldn't it make sense to move this check all the way up to the opening curly brace? Initializing the struct and integer is of no use, if the device is NULL.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is fine. You need all declarations to precede code in the C standard kernel targets.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to do that too but C best practices - declare variables first. Some compilers may have issue with the order.


config = dev->actconfig;
if (!config)
return NULL;
for (i = 0; i < config->desc.bNumInterfaces; i++)
Expand Down