Skip to content

Commit

Permalink
linux: Fix type of open() flags argument
Browse files Browse the repository at this point in the history
The second argument to open() is an int carrying flags (including
"access modes"). A third, optional argument has type mode_t, carrying
"file mode bits" for file permissions.

Also rename the variable to access_mode to make it more clear.

The type mismatch was caught by building with -Wconversion.

References libusb#1497

Signed-off-by: Tormod Volden <[email protected]>
  • Loading branch information
tormodvolden committed May 26, 2024
1 parent b00332d commit 8b50743
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions libusb/os/linux_usbfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ static int dev_has_config0(struct libusb_device *dev)
return 0;
}

static int get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent)
static int get_usbfs_fd(struct libusb_device *dev, int access_mode, int silent)
{
struct libusb_context *ctx = DEVICE_CTX(dev);
char path[24];
Expand All @@ -195,7 +195,7 @@ static int get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent)
snprintf(path, sizeof(path), USB_DEVTMPFS_PATH "/%03u/%03u",
dev->bus_number, dev->device_address);

fd = open(path, mode | O_CLOEXEC);
fd = open(path, access_mode | O_CLOEXEC);
if (fd != -1)
return fd; /* Success */

Expand All @@ -209,14 +209,14 @@ static int get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent)
/* Wait 10ms for USB device path creation.*/
nanosleep(&delay_ts, NULL);

fd = open(path, mode | O_CLOEXEC);
fd = open(path, access_mode | O_CLOEXEC);
if (fd != -1)
return fd; /* Success */
}

if (!silent) {
usbi_err(ctx, "libusb couldn't open USB device %s, errno=%d", path, errno);
if (errno == EACCES && mode == O_RDWR)
if (errno == EACCES && access_mode == O_RDWR)
usbi_err(ctx, "libusb requires write access to USB device nodes");
}

Expand Down
2 changes: 1 addition & 1 deletion libusb/version_nano.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define LIBUSB_NANO 11900
#define LIBUSB_NANO 11901

0 comments on commit 8b50743

Please sign in to comment.