]> git.baikalelectronics.ru Git - kernel.git/commitdiff
media: stkwebcam: move stk_camera_read_reg() scratch buffer to struct stk_camera
authorTom Rix <trix@redhat.com>
Sat, 12 Mar 2022 17:30:49 +0000 (18:30 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Fri, 13 May 2022 09:02:20 +0000 (11:02 +0200)
In stk_camera_read_reg() a single byte buffer is alloc-ed and
freed on every function call.  Since the size is known,
move the buffer to the struct stk_camera where it will be alloc-ed
and freed once.

Signed-off-by: Tom Rix <trix@redhat.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/usb/stkwebcam/stk-webcam.c
drivers/media/usb/stkwebcam/stk-webcam.h

index 5b822214ccc5c365fefaff62540e4c572f3941fc..787edb3d47c23d0ed62c05082a45252fb554e1b7 100644 (file)
@@ -150,25 +150,18 @@ int stk_camera_write_reg(struct stk_camera *dev, u16 index, u8 value)
 int stk_camera_read_reg(struct stk_camera *dev, u16 index, u8 *value)
 {
        struct usb_device *udev = dev->udev;
-       unsigned char *buf;
        int ret;
 
-       buf = kmalloc(sizeof(u8), GFP_KERNEL);
-       if (!buf)
-               return -ENOMEM;
-
        ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
                        0x00,
                        USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
                        0x00,
                        index,
-                       buf,
+                       &dev->read_reg_scratch,
                        sizeof(u8),
                        500);
        if (ret >= 0)
-               *value = *buf;
-
-       kfree(buf);
+               *value = dev->read_reg_scratch;
 
        if (ret < 0)
                return ret;
index 14519e5308b18fb53708403a0d298b7ac06d4e48..136decffe9ced2e6dcf6b091baaa9d3349b311e0 100644 (file)
@@ -105,6 +105,8 @@ struct stk_camera {
        struct list_head sio_avail;
        struct list_head sio_full;
        unsigned sequence;
+
+       u8 read_reg_scratch;
 };
 
 #define vdev_to_camera(d) container_of(d, struct stk_camera, vdev)