Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp589261pxb; Wed, 27 Jan 2021 16:01:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJw56JIp5qX3DL/TkyFp1vSlRrHNXAYRbQkaRF1abS+9XOzlLEq/I9a4WKFBrCShQ1CpEUA7 X-Received: by 2002:a05:6402:35c2:: with SMTP id z2mr11003445edc.34.1611792109064; Wed, 27 Jan 2021 16:01:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611792109; cv=none; d=google.com; s=arc-20160816; b=qul0ajLCiUobD+GFmyCl4tP82T6g95b7L3xFAt3oKLJedGtyTS9HA8z0dKwBvz7EPo bIA5IUk9l4b01DPJIalZeds34CxpYzje3gLzi6hcV4AEuRbW7z6Cbw9zWUjt79lPQXFJ CGY9Z7bxj273yqS5p7cHH90bjKx9Gb4ruVzxvbifw94bTc9SuyGqjzO6RwNDJN354nZt gY9xvHu+7BNP+u1ORDR/Fd76YMDoEMPwycyWpXk8uLLJ2UBRvNsVbZai1s/vQTBvnfrv tEymFCzdLntjl+bwTWon/pXRK5RuWE92Gd56n9hvJtIJC8U98kkDFUCpETU5Mx0Hspj2 tfUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=x34qqOW7FUNi+SIHF9ontS+mC7wswOjCLDhSNyAZ4OM=; b=kGxrwElGBsmOoSGJdiBTkJzr9tOKhGS0gqRMyOYacmRr/5psAd8cWGF/2DwOmyGxhs LHig32x+qpF6HWbRMbTg32mcSfz8x9Wb1Ncd3HtGOGe/N/6BtWY1Q6/mIdXIoebRhr5s WzY4tgT0egI1cMvCpWcaekbLOfhrEv5778ARzbP8OBXYLN4+BuNHHu8ua62O/5EI8Vko VJGjRzFxRIk/H0wLZ+uMIEjiCjJmTP7XT7oNoxSB12i0MkEpZFYbKf5dYpSCpand4iiV kg4CXhrLNKCCBuOnzYEotUl71N/H7ZtiuReslsVZs/4otHEqTSW5gxI+92lMP4FRFpIS f9Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=t+BAR4Z2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e6si1974494edz.361.2021.01.27.16.01.24; Wed, 27 Jan 2021 16:01:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=t+BAR4Z2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231708AbhA0OWc (ORCPT + 99 others); Wed, 27 Jan 2021 09:22:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:42832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbhA0OWW (ORCPT ); Wed, 27 Jan 2021 09:22:22 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0075F206C2; Wed, 27 Jan 2021 14:21:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611757299; bh=h4KlcOqVpt+f7NayTo74/7IODdEHC+WplK/87YEXFY4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=t+BAR4Z2Pu7DB0HXkvxM8DQQPBVAvjYbjZNjN0spoa7Ztki/hQ424j+lXdArN+uEw BhQ1CNUU3mfWmpwfcUOBE712yPuI85fwfJI5KKgsCtLkRS/e/b2egGbOGR/l2/mCyt Z9SeVCTp7hhFFuFz0IEEbva52Udw6SZkDNeYB+pYsBXFUhaVbPsb3CbPcxTd1aOWJE PKMPVG4hwpC0AI78K8KvRW5DL3WJwMNEykMtAY8Nx3WwpaGejWeQlsrHDJj8kCjGaK C9yOw7ik0PeNrT18U0pg35wBODeNkkyCM2wDOr4x2NsJvNZxxj39MYZQPOXjvgaM3V 42+xI7VxayVEQ== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1l4lhe-0001py-TN; Wed, 27 Jan 2021 15:21:50 +0100 Date: Wed, 27 Jan 2021 15:21:50 +0100 From: Johan Hovold To: Anant Thazhemadam Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 03/12] usb: misc: cytherm: update to use usb_control_msg_recv() Message-ID: References: <20210126183403.911653-1-anant.thazhemadam@gmail.com> <20210126183403.911653-4-anant.thazhemadam@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210126183403.911653-4-anant.thazhemadam@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 27, 2021 at 12:03:54AM +0530, Anant Thazhemadam wrote: > 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, the instance of usb_control_msg() has been replaced with > usb_control_msg_recv(). > > The return value checking enforced by callers of the updated function have > also been appropriately updated. > > Signed-off-by: Anant Thazhemadam > --- > drivers/usb/misc/cytherm.c | 128 +++++++++++++------------------------ > 1 file changed, 43 insertions(+), 85 deletions(-) > > diff --git a/drivers/usb/misc/cytherm.c b/drivers/usb/misc/cytherm.c > index 3e3802aaefa3..2ca36ea5b76a 100644 > --- a/drivers/usb/misc/cytherm.c > +++ b/drivers/usb/misc/cytherm.c > @@ -51,12 +51,12 @@ static int vendor_command(struct usb_device *dev, unsigned char request, > unsigned char value, unsigned char index, > void *buf, int size) > { > - return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), > - request, > - USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER, > - value, > - index, buf, size, > - USB_CTRL_GET_TIMEOUT); > + return usb_control_msg_recv(dev, 0, > + request, > + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER, > + value, > + index, buf, size, > + USB_CTRL_GET_TIMEOUT, GFP_KERNEL); > } > > > @@ -78,33 +78,27 @@ static ssize_t brightness_store(struct device *dev, struct device_attribute *att > struct usb_interface *intf = to_usb_interface(dev); > struct usb_cytherm *cytherm = usb_get_intfdata(intf); > > - unsigned char *buffer; > + unsigned char buffer[8]; > int retval; > - > - buffer = kmalloc(8, GFP_KERNEL); > - if (!buffer) > - return 0; > > cytherm->brightness = simple_strtoul(buf, NULL, 10); > - > + > if (cytherm->brightness > 0xFF) > cytherm->brightness = 0xFF; > else if (cytherm->brightness < 0) > cytherm->brightness = 0; > - > + > /* Set brightness */ > retval = vendor_command(cytherm->udev, WRITE_RAM, BRIGHTNESS, > - cytherm->brightness, buffer, 8); > - if (retval) > - dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval); > + cytherm->brightness, &buffer, 8); > + if (!retval) > + dev_dbg(&cytherm->udev->dev, "brightness set correctly\n"); > /* Inform µC that we have changed the brightness setting */ > retval = vendor_command(cytherm->udev, WRITE_RAM, BRIGHTNESS_SEM, > - 0x01, buffer, 8); > - if (retval) > - dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval); > - > - kfree(buffer); > - > + 0x01, &buffer, 8); > + if (!retval) > + dev_dbg(&cytherm->udev->dev, "µC informed of change in brightness setting\n"); > + > return count; > } This driver looks like it could have the same origin as the one touched by the previous patch, and likewise this patch suffers from a similar problem in that the driver always provides an 8-byte buffer but appears to expect short reads (which would no be treated as errors). You could consider adding the missing short read sanity checks, but I'm afraid the new helpers are not a good fit here either. Johan