Commit 939ffb17 authored by Aniroop Mathur's avatar Aniroop Mathur Committed by Dmitry Torokhov

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: default avatarAniroop Mathur <aniroop.mathur@gmail.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 9c7d66fa
...@@ -527,14 +527,14 @@ EXPORT_SYMBOL(gameport_set_phys); ...@@ -527,14 +527,14 @@ EXPORT_SYMBOL(gameport_set_phys);
*/ */
static void gameport_init_port(struct gameport *gameport) static void gameport_init_port(struct gameport *gameport)
{ {
static atomic_t gameport_no = ATOMIC_INIT(0); static atomic_t gameport_no = ATOMIC_INIT(-1);
__module_get(THIS_MODULE); __module_get(THIS_MODULE);
mutex_init(&gameport->drv_mutex); mutex_init(&gameport->drv_mutex);
device_initialize(&gameport->dev); device_initialize(&gameport->dev);
dev_set_name(&gameport->dev, "gameport%lu", dev_set_name(&gameport->dev, "gameport%lu",
(unsigned long)atomic_inc_return(&gameport_no) - 1); (unsigned long)atomic_inc_return(&gameport_no));
gameport->dev.bus = &gameport_bus; gameport->dev.bus = &gameport_bus;
gameport->dev.release = gameport_release_port; gameport->dev.release = gameport_release_port;
if (gameport->parent) if (gameport->parent)
......
...@@ -884,8 +884,8 @@ static void xpad_led_set(struct led_classdev *led_cdev, ...@@ -884,8 +884,8 @@ static void xpad_led_set(struct led_classdev *led_cdev,
static int xpad_led_probe(struct usb_xpad *xpad) static int xpad_led_probe(struct usb_xpad *xpad)
{ {
static atomic_t led_seq = ATOMIC_INIT(0); static atomic_t led_seq = ATOMIC_INIT(-1);
long led_no; unsigned long led_no;
struct xpad_led *led; struct xpad_led *led;
struct led_classdev *led_cdev; struct led_classdev *led_cdev;
int error; int error;
...@@ -897,9 +897,9 @@ static int xpad_led_probe(struct usb_xpad *xpad) ...@@ -897,9 +897,9 @@ static int xpad_led_probe(struct usb_xpad *xpad)
if (!led) if (!led)
return -ENOMEM; return -ENOMEM;
led_no = (long)atomic_inc_return(&led_seq) - 1; led_no = atomic_inc_return(&led_seq);
snprintf(led->name, sizeof(led->name), "xpad%ld", led_no); snprintf(led->name, sizeof(led->name), "xpad%lu", led_no);
led->xpad = xpad; led->xpad = xpad;
led_cdev = &led->led_cdev; led_cdev = &led->led_cdev;
......
...@@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id) ...@@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
static int ims_pcu_init_application_mode(struct ims_pcu *pcu) static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
{ {
static atomic_t device_no = ATOMIC_INIT(0); static atomic_t device_no = ATOMIC_INIT(-1);
const struct ims_pcu_device_info *info; const struct ims_pcu_device_info *info;
int error; int error;
...@@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu) ...@@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
} }
/* Device appears to be operable, complete initialization */ /* Device appears to be operable, complete initialization */
pcu->device_no = atomic_inc_return(&device_no) - 1; pcu->device_no = atomic_inc_return(&device_no);
/* /*
* PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
......
...@@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev) ...@@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
*/ */
static void serio_init_port(struct serio *serio) static void serio_init_port(struct serio *serio)
{ {
static atomic_t serio_no = ATOMIC_INIT(0); static atomic_t serio_no = ATOMIC_INIT(-1);
__module_get(THIS_MODULE); __module_get(THIS_MODULE);
...@@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio) ...@@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
mutex_init(&serio->drv_mutex); mutex_init(&serio->drv_mutex);
device_initialize(&serio->dev); device_initialize(&serio->dev);
dev_set_name(&serio->dev, "serio%lu", dev_set_name(&serio->dev, "serio%lu",
(unsigned long)atomic_inc_return(&serio_no) - 1); (unsigned long)atomic_inc_return(&serio_no));
serio->dev.bus = &serio_bus; serio->dev.bus = &serio_bus;
serio->dev.release = serio_release_port; serio->dev.release = serio_release_port;
serio->dev.groups = serio_device_attr_groups; serio->dev.groups = serio_device_attr_groups;
......
...@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data, ...@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
static int serio_raw_connect(struct serio *serio, struct serio_driver *drv) static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
{ {
static atomic_t serio_raw_no = ATOMIC_INIT(0); static atomic_t serio_raw_no = ATOMIC_INIT(-1);
struct serio_raw *serio_raw; struct serio_raw *serio_raw;
int err; int err;
...@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv) ...@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
} }
snprintf(serio_raw->name, sizeof(serio_raw->name), snprintf(serio_raw->name, sizeof(serio_raw->name),
"serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1); "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no));
kref_init(&serio_raw->kref); kref_init(&serio_raw->kref);
INIT_LIST_HEAD(&serio_raw->client_list); INIT_LIST_HEAD(&serio_raw->client_list);
init_waitqueue_head(&serio_raw->wait); init_waitqueue_head(&serio_raw->wait);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment