Skip to content

Commit 6078091

Browse files
andy-shevdtor
authored andcommitted
Input: evdev - switch to bitmap API
Switch to bitmap API, i.e. bitmap_alloc(), bitmap_zalloc(), to show clearly what we are allocating. Besides that it returns pointer of bitmap type instead of opaque void *. While here, replace memcpy() with bitmap_copy() for sake of consistency. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 4e2ec39 commit 6078091

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

‎drivers/input/evdev.c‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ static int evdev_release(struct inode *inode, struct file *file)
481481
evdev_detach_client(evdev, client);
482482

483483
for (i = 0; i < EV_CNT; ++i)
484-
kfree(client->evmasks[i]);
484+
bitmap_free(client->evmasks[i]);
485485

486486
kvfree(client);
487487

@@ -925,17 +925,15 @@ static int evdev_handle_get_val(struct evdev_client *client,
925925
{
926926
int ret;
927927
unsigned long *mem;
928-
size_t len;
929928

930-
len = BITS_TO_LONGS(maxbit) * sizeof(unsigned long);
931-
mem = kmalloc(len, GFP_KERNEL);
929+
mem = bitmap_alloc(maxbit, GFP_KERNEL);
932930
if (!mem)
933931
return -ENOMEM;
934932

935933
spin_lock_irq(&dev->event_lock);
936934
spin_lock(&client->buffer_lock);
937935

938-
memcpy(mem, bits, len);
936+
bitmap_copy(mem, bits, maxbit);
939937

940938
spin_unlock(&dev->event_lock);
941939

@@ -947,7 +945,7 @@ static int evdev_handle_get_val(struct evdev_client *client,
947945
if (ret < 0)
948946
evdev_queue_syn_dropped(client);
949947

950-
kfree(mem);
948+
bitmap_free(mem);
951949

952950
return ret;
953951
}
@@ -1003,13 +1001,13 @@ static int evdev_set_mask(struct evdev_client *client,
10031001
if (!cnt)
10041002
return 0;
10051003

1006-
mask = kcalloc(sizeof(unsigned long), BITS_TO_LONGS(cnt), GFP_KERNEL);
1004+
mask = bitmap_zalloc(cnt, GFP_KERNEL);
10071005
if (!mask)
10081006
return -ENOMEM;
10091007

10101008
error = bits_from_user(mask, cnt - 1, codes_size, codes, compat);
10111009
if (error < 0) {
1012-
kfree(mask);
1010+
bitmap_free(mask);
10131011
return error;
10141012
}
10151013

@@ -1018,7 +1016,7 @@ static int evdev_set_mask(struct evdev_client *client,
10181016
client->evmasks[type] = mask;
10191017
spin_unlock_irqrestore(&client->buffer_lock, flags);
10201018

1021-
kfree(oldmask);
1019+
bitmap_free(oldmask);
10221020

10231021
return 0;
10241022
}

0 commit comments

Comments
 (0)