Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5488891pxb; Wed, 26 Jan 2022 13:14:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJyCt8NsvPVHGQqElW1YQPJdqJC+rxp6UAteEYjj5AchgtPSsymmtq01nR6JHyY3zYR8OIuw X-Received: by 2002:aa7:9904:: with SMTP id z4mr300797pff.68.1643231655547; Wed, 26 Jan 2022 13:14:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643231655; cv=none; d=google.com; s=arc-20160816; b=s2g+qFjw5ximMWXvbjAFXbovlWhw5VTH+mIuBRfJXbFF7SZze479y2f8w6Ml48ne2V g+QDKTohmCjiplde8KCFKDRI5bsmMPCgHbWfWH7hhwxNT6lz4B/EgiBc0UAuTREGnr4G qIA1SFVgQIwbRCe5VDhOyO3Zh7MEKOaVF5gsGc7ucGmpMJJloLpEOFR6MCc20qiD2sS2 bmLDIxXtm9U0+QfgUJqyygl1FQhe+8uQbrCK9wI/YETNbb5c1PLMPTVcgGKPO9TFVbOn ALQnqWxY/wHTI6vVQLiiedX0w3U6qU57KjqHSoqh+YUJ9tRZquW4Ff1jSfzrLbm7jJHj 701w== 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=0bzh9BBx7SUhSB7QZlsU0bTVlNs9Vp1QC6JELikkNS8=; b=0RxSmyuAbATYNxNdJxIMHR3cspSu1+lM+sYBC1AkDGRSZTJUndxF1jkpnsz7NvtsDt oF7wStx7fhiHhm1GXevJEZ7/Vnw6zOFvAKdDHFSy6+Yd/0xQPwa8M2obX1o3wC0F+EQ8 7AekkWmC3xNj+xXbTg9Eh00vgpQP+tMnYhV3jSyPj81hy1083opupWWg6S4SxN+zI4R2 AM2Lg4WjU16Z9YFSauL70e3mVqEGR1OHGKp49GoMEn3OE8QSjdbovchUqb6CjSlb4gIX sew9vbqT2aveKlwUBO8tBmJ0WYSLfkjwFLiXH5N58prfCAQ2xXjly7fVDMZK3y9UnPof AIEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yhbbSDyH; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x17si341460pfa.82.2022.01.26.13.14.03; Wed, 26 Jan 2022 13:14:15 -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=@linuxfoundation.org header.s=korg header.b=yhbbSDyH; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241206AbiAZMVh (ORCPT + 99 others); Wed, 26 Jan 2022 07:21:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241194AbiAZMVh (ORCPT ); Wed, 26 Jan 2022 07:21:37 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FC71C06161C; Wed, 26 Jan 2022 04:21:36 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 62381B81CBB; Wed, 26 Jan 2022 12:21:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84CCBC340E6; Wed, 26 Jan 2022 12:21:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643199694; bh=EVVNFMBmRDZrmd8r75px+PJ5SYyURniMHufo4K/7jfM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=yhbbSDyHm6glrzoBDNTPUrFwriA2sJXg8gNGYLm+2xfigHsfOLVdcBC9/NGnxXtxS 238VXm/GIWTCt6z1fnvw7loVpIFzFI10Ss/YSVtQ1dcYZcesIBx/HiWfqYZ0fJgymj FnN3AbPi735t1kZLZX2xe/W6ywu5qr4mJc2bhSYA= Date: Wed, 26 Jan 2022 13:21:31 +0100 From: Greg KH To: =?utf-8?B?6Zmz5YGJ6YqY?= Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, balbi@kernel.org, Maciej =?utf-8?Q?=C5=BBenczykowski?= Subject: Re: [PATCH] usb: gadget: function: Fix returning incorrect PNP string Message-ID: References: <20220105040439.3182-1-jj251510319013@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 07, 2022 at 10:37:19AM +0800, 陳偉銘 wrote: > Greg KH 於 2022年1月6日 週四 下午10:35寫道: > > > > On Wed, Jan 05, 2022 at 12:04:39PM +0800, Wei Ming Chen wrote: > > > There will be 2 leading bytes indicating the total length of > > > the PNP string, so I think we should add value by 2, otherwise > > > the PNP string copied to user will not contain the last 2 bytes > > > > > > Signed-off-by: Wei Ming Chen > > > --- > > > drivers/usb/gadget/function/f_printer.c | 4 +++- > > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c > > > index abec5c58f525..3fb00fd0b5ee 100644 > > > --- a/drivers/usb/gadget/function/f_printer.c > > > +++ b/drivers/usb/gadget/function/f_printer.c > > > @@ -1005,9 +1005,11 @@ static int printer_func_setup(struct usb_function *f, > > > break; > > > } > > > value = strlen(dev->pnp_string); > > > + memcpy(buf + 2, dev->pnp_string, value); > > > + > > > + value += 2; > > > buf[0] = (value >> 8) & 0xFF; > > > buf[1] = value & 0xFF; > > > - memcpy(buf + 2, dev->pnp_string, value); > > > DBG(dev, "1284 PNP String: %x %s\n", value, > > > dev->pnp_string); > > > break; > > > -- > > > 2.25.1 > > > > > > > Are you sure this is correct? > > > > How is this related to this recent thread: > > https://lore.kernel.org/all/CAKjGFBUdjXcZoVV4jdrgTz4rKThTfZAK4CqreKmBZ4KHE+K1GA@mail.gmail.com/#t > > > > your change is different from what is proposed there, why? > > I didn’t notice this thread before I send this patch, I think the > concept of my change is similar to Volodymyr Lisivka’s change, he/she > introduced a separate variable for the PNP string length, I think it > may be clearer and more readable than just “value += 2” > > > Another thing that I am not too sure whether I am correct is this line of code > > DBG(dev, "1284 PNP String: %x %s\n", value, > dev->pnp_string); > > What Volodymyr Lisivka changed is like this > > DBG(dev, "1284 PNP String: %x %s\n", pnp_length, > dev->pnp_string); > > In my change, “value” equals to “pnp_length + 2” in Volodymyr > Lisivka’s change, and I think we should print “the PNP string length + > 2” instead of “the PNP string length”? > I do not know, I suggest you two work together to get the correct fix submitted. thanks, greg k-h