usb: gadget: u_serial: fix coverity warning: negative index at array
Subsystems (2)
PATCH 1/1 usb: gadget: u_serial: fix coverity warning: negative index at array
This issue has been reported by coverity scanner.
Replace "int portnum" by "unsigned int", this void negative index at array.
--- drivers/usb/gadget/function/u_serial.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/function/u_serial.c +2 -2
@@ -587,7 +587,7 @@ static int gs_start_io(struct gs_port *port)*/ static int gs_open (struct tty_struct *tty,struct file *file) { -int port_num = tty->index; +unsigned int port_num = tty->index;struct gs_port *port;int status =0 ;
@@ -1211,7 +1211,7 @@ int gserial_alloc_line_no_console(unsigned char *line_num)struct gs_port *port;struct device *tty_dev;int ret; -int port_num; +unsigned int port_num; coding.dwDTERate =cpu_to_le32 (9600 ); coding.bCharFormat =8 ;
Signature · 1 line
1.7.9.5
Quoted 6 lines · Macpaul Lin
This issue has been reported by coverity scanner.
Replace "int portnum" by "unsigned int", this void negative index at array.Signed-off-by Stan Lu <[email protected]>Signed-off-by Macpaul Lin <[email protected]>
please rebase on testing/fixes
error: patch failed: drivers/usb/gadget/function/u_serial.c:587
error: drivers/usb/gadget/function/u_serial.c: patch does not apply
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Applying: usb: gadget: u_serial: fix coverity warning: negative index at array Patch failed at 0001 usb: gadget: u_serial: fix coverity warning: negative index at array When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Signature · 1 line
balbi
Quoted 3 lines · Macpaul Lin
This issue has been reported by coverity scanner.
Replace "int portnum" by "unsigned int", this void negative index at array.
Can you please explain this more fully? Why does coverity think the code might use a negative array index? Is there some possibility that the portnum value might actually be negative?
It's noticeable that your patch doesn't actually change any values, only the type. This means that if the code was buggy before, it's still buggy. Alternatively, if the code wasn't buggy before then coverity got a false positive, so no change should be needed.
Alan Stern
Quoted 30 lines
Signed-off-by Stan Lu <[email protected]>Signed-off-by Macpaul Lin <[email protected]>--- drivers/usb/gadget/function/u_serial.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/usb/gadget/function/u_serial.c +2
-2@@ -587,7 +587,7 @@ static int gs_start_io(struct gs_port *port)*/ static int gs_open (struct tty_struct *tty,struct file *file) { -int port_num = tty->index; +unsigned int port_num = tty->index;struct gs_port *port;int status =0 ;@@ -1211,7 +1211,7 @@ int gserial_alloc_line_no_console(unsigned char *line_num)struct gs_port *port;struct device *tty_dev;int ret; -int port_num; +unsigned int port_num; coding.dwDTERate =cpu_to_le32 (9600 ); coding.bCharFormat =8 ;Signature · 1 line
1.7.9.5