Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: initialize device counter variables with -1

Let's initialize atomic_t variables keeping track of number of various
devices created so far with -1 in order to avoid extra subtraction
operation.

Signed-off-by: Aniroop Mathur <aniroop.mathur@gmail.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Aniroop Mathur and committed by
Dmitry Torokhov
939ffb17 9c7d66fa

+12 -12
+2 -2
drivers/input/gameport/gameport.c
··· 527 527 */ 528 528 static void gameport_init_port(struct gameport *gameport) 529 529 { 530 - static atomic_t gameport_no = ATOMIC_INIT(0); 530 + static atomic_t gameport_no = ATOMIC_INIT(-1); 531 531 532 532 __module_get(THIS_MODULE); 533 533 534 534 mutex_init(&gameport->drv_mutex); 535 535 device_initialize(&gameport->dev); 536 536 dev_set_name(&gameport->dev, "gameport%lu", 537 - (unsigned long)atomic_inc_return(&gameport_no) - 1); 537 + (unsigned long)atomic_inc_return(&gameport_no)); 538 538 gameport->dev.bus = &gameport_bus; 539 539 gameport->dev.release = gameport_release_port; 540 540 if (gameport->parent)
+4 -4
drivers/input/joystick/xpad.c
··· 884 884 885 885 static int xpad_led_probe(struct usb_xpad *xpad) 886 886 { 887 - static atomic_t led_seq = ATOMIC_INIT(0); 888 - long led_no; 887 + static atomic_t led_seq = ATOMIC_INIT(-1); 888 + unsigned long led_no; 889 889 struct xpad_led *led; 890 890 struct led_classdev *led_cdev; 891 891 int error; ··· 897 897 if (!led) 898 898 return -ENOMEM; 899 899 900 - led_no = (long)atomic_inc_return(&led_seq) - 1; 900 + led_no = atomic_inc_return(&led_seq); 901 901 902 - snprintf(led->name, sizeof(led->name), "xpad%ld", led_no); 902 + snprintf(led->name, sizeof(led->name), "xpad%lu", led_no); 903 903 led->xpad = xpad; 904 904 905 905 led_cdev = &led->led_cdev;
+2 -2
drivers/input/misc/ims-pcu.c
··· 1851 1851 1852 1852 static int ims_pcu_init_application_mode(struct ims_pcu *pcu) 1853 1853 { 1854 - static atomic_t device_no = ATOMIC_INIT(0); 1854 + static atomic_t device_no = ATOMIC_INIT(-1); 1855 1855 1856 1856 const struct ims_pcu_device_info *info; 1857 1857 int error; ··· 1882 1882 } 1883 1883 1884 1884 /* Device appears to be operable, complete initialization */ 1885 - pcu->device_no = atomic_inc_return(&device_no) - 1; 1885 + pcu->device_no = atomic_inc_return(&device_no); 1886 1886 1887 1887 /* 1888 1888 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
+2 -2
drivers/input/serio/serio.c
··· 514 514 */ 515 515 static void serio_init_port(struct serio *serio) 516 516 { 517 - static atomic_t serio_no = ATOMIC_INIT(0); 517 + static atomic_t serio_no = ATOMIC_INIT(-1); 518 518 519 519 __module_get(THIS_MODULE); 520 520 ··· 525 525 mutex_init(&serio->drv_mutex); 526 526 device_initialize(&serio->dev); 527 527 dev_set_name(&serio->dev, "serio%lu", 528 - (unsigned long)atomic_inc_return(&serio_no) - 1); 528 + (unsigned long)atomic_inc_return(&serio_no)); 529 529 serio->dev.bus = &serio_bus; 530 530 serio->dev.release = serio_release_port; 531 531 serio->dev.groups = serio_device_attr_groups;
+2 -2
drivers/input/serio/serio_raw.c
··· 292 292 293 293 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv) 294 294 { 295 - static atomic_t serio_raw_no = ATOMIC_INIT(0); 295 + static atomic_t serio_raw_no = ATOMIC_INIT(-1); 296 296 struct serio_raw *serio_raw; 297 297 int err; 298 298 ··· 303 303 } 304 304 305 305 snprintf(serio_raw->name, sizeof(serio_raw->name), 306 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1); 306 + "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no)); 307 307 kref_init(&serio_raw->kref); 308 308 INIT_LIST_HEAD(&serio_raw->client_list); 309 309 init_waitqueue_head(&serio_raw->wait);