qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

ui/input-linux: Do not ignore ioctl() return value

Fix warnings reported by Clang static code analyzer:

CC ui/input-linux.o
ui/input-linux.c:343:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_REL, sizeof(relmap)), &relmap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:351:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_ABS, sizeof(absmap)), &absmap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:354:13: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGABS(ABS_X), &absinfo);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:357:13: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGABS(ABS_Y), &absinfo);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:365:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_KEY, sizeof(keymap)), keymap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:366:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGKEY(sizeof(keystate)), keystate);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reported-by: Clang Static Analyzer
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Message-id: 20200322161219.17757-1-philmd@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

authored by

Philippe Mathieu-Daudé and committed by
Gerd Hoffmann
112c37a6 736cf607

+27 -2
+27 -2
ui/input-linux.c
··· 334 334 335 335 rc = ioctl(il->fd, EVIOCGBIT(0, sizeof(evtmap)), &evtmap); 336 336 if (rc < 0) { 337 - error_setg(errp, "%s: failed to read event bits", il->evdev); 338 - goto err_close; 337 + goto err_read_event_bits; 339 338 } 340 339 341 340 if (evtmap & (1 << EV_REL)) { 342 341 relmap = 0; 343 342 rc = ioctl(il->fd, EVIOCGBIT(EV_REL, sizeof(relmap)), &relmap); 343 + if (rc < 0) { 344 + goto err_read_event_bits; 345 + } 344 346 if (relmap & (1 << REL_X)) { 345 347 il->has_rel_x = true; 346 348 } ··· 349 351 if (evtmap & (1 << EV_ABS)) { 350 352 absmap = 0; 351 353 rc = ioctl(il->fd, EVIOCGBIT(EV_ABS, sizeof(absmap)), &absmap); 354 + if (rc < 0) { 355 + goto err_read_event_bits; 356 + } 352 357 if (absmap & (1 << ABS_X)) { 353 358 il->has_abs_x = true; 354 359 rc = ioctl(il->fd, EVIOCGABS(ABS_X), &absinfo); 360 + if (rc < 0) { 361 + error_setg(errp, "%s: failed to get get absolute X value", 362 + il->evdev); 363 + goto err_close; 364 + } 355 365 il->abs_x_min = absinfo.minimum; 356 366 il->abs_x_max = absinfo.maximum; 357 367 rc = ioctl(il->fd, EVIOCGABS(ABS_Y), &absinfo); 368 + if (rc < 0) { 369 + error_setg(errp, "%s: failed to get get absolute Y value", 370 + il->evdev); 371 + goto err_close; 372 + } 358 373 il->abs_y_min = absinfo.minimum; 359 374 il->abs_y_max = absinfo.maximum; 360 375 } ··· 363 378 if (evtmap & (1 << EV_KEY)) { 364 379 memset(keymap, 0, sizeof(keymap)); 365 380 rc = ioctl(il->fd, EVIOCGBIT(EV_KEY, sizeof(keymap)), keymap); 381 + if (rc < 0) { 382 + goto err_read_event_bits; 383 + } 366 384 rc = ioctl(il->fd, EVIOCGKEY(sizeof(keystate)), keystate); 385 + if (rc < 0) { 386 + error_setg(errp, "%s: failed to get global key state", il->evdev); 387 + goto err_close; 388 + } 367 389 for (i = 0; i < KEY_CNT; i++) { 368 390 if (keymap[i / 8] & (1 << (i % 8))) { 369 391 if (linux_is_button(i)) { ··· 389 411 QTAILQ_INSERT_TAIL(&inputs, il, next); 390 412 il->initialized = true; 391 413 return; 414 + 415 + err_read_event_bits: 416 + error_setg(errp, "%s: failed to read event bits", il->evdev); 392 417 393 418 err_close: 394 419 close(il->fd);