Input: evdev - use struct_size() in kzalloc() and vzalloc()
[sfrench/cifs-2.6.git] / drivers / input / evdev.c
index f48369d6f3a0f36ef1ab412ac95a2b2b51d55b3d..ee8dd8b1b09e9513578682479227d5663fae770d 100644 (file)
@@ -503,14 +503,13 @@ static int evdev_open(struct inode *inode, struct file *file)
 {
        struct evdev *evdev = container_of(inode->i_cdev, struct evdev, cdev);
        unsigned int bufsize = evdev_compute_buffer_size(evdev->handle.dev);
-       unsigned int size = sizeof(struct evdev_client) +
-                                       bufsize * sizeof(struct input_event);
        struct evdev_client *client;
        int error;
 
-       client = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
+       client = kzalloc(struct_size(client, buffer, bufsize),
+                        GFP_KERNEL | __GFP_NOWARN);
        if (!client)
-               client = vzalloc(size);
+               client = vzalloc(struct_size(client, buffer, bufsize));
        if (!client)
                return -ENOMEM;