Skip to content

Commit

Permalink
open : 0 is a valid file descriptor.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdelnero committed Nov 6, 2023
1 parent 699def1 commit 3f7f088
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/usb_gadget.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ int init_ep(usb_gadget * ctx,int index,int ffs_mode)

PRINT_DEBUG("Init end point %s (%d)",ctx->ep_path[index],index);
fd = open(ctx->ep_path[index], O_RDWR);
if ( fd <= 0 )
if ( fd < 0 )
{
PRINT_ERROR("init_ep : Endpoint %s (%d) init failed ! : Can't open the endpoint ! (error %d - %m)",ctx->ep_path[index],index,fd);
goto init_ep_error;
Expand Down Expand Up @@ -361,18 +361,22 @@ int init_ep(usb_gadget * ctx,int index,int ffs_mode)
return fd;

init_ep_error:
return 0;

if(fd >= 0)
close(fd);

return -1;
}

int init_eps(usb_gadget * ctx, int ffs_mode)
{
if( !init_ep(ctx, EP_DESCRIPTOR_IN, ffs_mode) )
if( init_ep(ctx, EP_DESCRIPTOR_IN, ffs_mode) < 0 )
goto init_eps_error;

if( !init_ep(ctx, EP_DESCRIPTOR_OUT, ffs_mode) )
if( init_ep(ctx, EP_DESCRIPTOR_OUT, ffs_mode) < 0 )
goto init_eps_error;

if( !init_ep(ctx, EP_DESCRIPTOR_INT_IN, ffs_mode) )
if( init_ep(ctx, EP_DESCRIPTOR_INT_IN, ffs_mode) < 0 )
goto init_eps_error;

return 0;
Expand Down Expand Up @@ -902,7 +906,6 @@ usb_gadget * init_usb_mtp_gadget(mtp_ctx * ctx)
usbctx = malloc(sizeof(usb_gadget));
if(usbctx)
{

memset(usbctx,0,sizeof(usb_gadget));

usbctx->usb_device = -1;
Expand Down Expand Up @@ -942,7 +945,7 @@ usb_gadget * init_usb_mtp_gadget(mtp_ctx * ctx)

usbctx->usb_device = open(ctx->usb_cfg.usb_device_path, O_RDWR|O_SYNC);

if (usbctx->usb_device <= 0)
if (usbctx->usb_device < 0)
{
PRINT_ERROR("init_usb_mtp_gadget : Unable to open %s (%m)", ctx->usb_cfg.usb_device_path);
goto init_error;
Expand Down Expand Up @@ -1094,7 +1097,7 @@ usb_gadget * init_usb_mtp_gadget(mtp_ctx * ctx)

deinit_usb_mtp_gadget(usbctx);

return 0;
return NULL;
}

void deinit_usb_mtp_gadget(usb_gadget * usbctx)
Expand Down

0 comments on commit 3f7f088

Please sign in to comment.