[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20201129160612.1908074-2-anant.thazhemadam@gmail.com>
Date: Sun, 29 Nov 2020 21:35:58 +0530
From: Anant Thazhemadam <anant.thazhemadam@...il.com>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Gustavo A. R. Silva" <gustavoars@...nel.org>,
Xu Wang <vulab@...as.ac.cn>,
Liu Shixin <liushixin2@...wei.com>,
Anant Thazhemadam <anant.thazhemadam@...il.com>
Cc: linux-usb@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH 01/15] usb: misc: appledisplay: update to use the usb_control_msg_{send|recv}() API
The newer usb_control_msg_{send|recv}() API are an improvement on the
existing usb_control_msg() as it ensures that a short read/write is treated
as an error, data can be used off the stack, and raw usb pipes need not be
created in the calling functions.
For this reason, instances of usb_control_msg() have been replaced with
usb_control_msg_{recv|send}(), and all return value checking
conditions have also been modified appropriately.
Signed-off-by: Anant Thazhemadam <anant.thazhemadam@...il.com>
---
drivers/usb/misc/appledisplay.c | 46 ++++++++++++++-------------------
1 file changed, 19 insertions(+), 27 deletions(-)
diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
index c8098e9b432e..117deb2fdc29 100644
--- a/drivers/usb/misc/appledisplay.c
+++ b/drivers/usb/misc/appledisplay.c
@@ -132,21 +132,17 @@ static int appledisplay_bl_update_status(struct backlight_device *bd)
pdata->msgdata[0] = 0x10;
pdata->msgdata[1] = bd->props.brightness;
- retval = usb_control_msg(
- pdata->udev,
- usb_sndctrlpipe(pdata->udev, 0),
- USB_REQ_SET_REPORT,
- USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
- ACD_USB_BRIGHTNESS,
- 0,
- pdata->msgdata, 2,
- ACD_USB_TIMEOUT);
+ retval = usb_control_msg_send(pdata->udev,
+ 0,
+ USB_REQ_SET_REPORT,
+ USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
+ ACD_USB_BRIGHTNESS,
+ 0,
+ pdata->msgdata, 2,
+ ACD_USB_TIMEOUT, GFP_KERNEL);
mutex_unlock(&pdata->sysfslock);
- if (retval < 0)
- return retval;
- else
- return 0;
+ return retval;
}
static int appledisplay_bl_get_brightness(struct backlight_device *bd)
@@ -155,21 +151,17 @@ static int appledisplay_bl_get_brightness(struct backlight_device *bd)
int retval, brightness;
mutex_lock(&pdata->sysfslock);
- retval = usb_control_msg(
- pdata->udev,
- usb_rcvctrlpipe(pdata->udev, 0),
- USB_REQ_GET_REPORT,
- USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
- ACD_USB_BRIGHTNESS,
- 0,
- pdata->msgdata, 2,
- ACD_USB_TIMEOUT);
- if (retval < 2) {
- if (retval >= 0)
- retval = -EMSGSIZE;
- } else {
+ retval = usb_control_msg_recv(pdata->udev,
+ 0,
+ USB_REQ_GET_REPORT,
+ USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
+ ACD_USB_BRIGHTNESS,
+ 0,
+ pdata->msgdata, 2,
+ ACD_USB_TIMEOUT, GFP_KERNEL);
+ if (retval == 0)
brightness = pdata->msgdata[1];
- }
+
mutex_unlock(&pdata->sysfslock);
if (retval < 0)
--
2.25.1
Powered by blists - more mailing lists