Re: [PATCH] media: stkwebcam: move stk_camera_read_reg() scratch buffer to struct stk_camera

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Trix,

On 3/12/22 20:30, trix@xxxxxxxxxx wrote:
From: Tom Rix <trix@xxxxxxxxxx>

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@xxxxxxxxxx>
---
  drivers/media/usb/stkwebcam/stk-webcam.c | 11 ++---------
  drivers/media/usb/stkwebcam/stk-webcam.h |  2 ++
  2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c b/drivers/media/usb/stkwebcam/stk-webcam.c
index 5b822214ccc5c..787edb3d47c23 100644
--- a/drivers/media/usb/stkwebcam/stk-webcam.c
+++ b/drivers/media/usb/stkwebcam/stk-webcam.c
@@ -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);


Wouldn't it be better to move to modern USB API like usb_control_msg_recv()?

This API does not require buffer to be allocated via kmalloc(), so you will be able to use value directly.




With regards,
Pavel Skripkin



[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux