Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E75FFC433EF for ; Wed, 8 Dec 2021 21:36:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238228AbhLHVka (ORCPT ); Wed, 8 Dec 2021 16:40:30 -0500 Received: from netrider.rowland.org ([192.131.102.5]:32965 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S229735AbhLHVk2 (ORCPT ); Wed, 8 Dec 2021 16:40:28 -0500 Received: (qmail 588025 invoked by uid 1000); 8 Dec 2021 16:36:55 -0500 Date: Wed, 8 Dec 2021 16:36:55 -0500 From: Alan Stern To: Guo Zhengkui Cc: Greg Kroah-Hartman , Li Jun , Kishon Vijay Abraham I , Andrey Konovalov , Peter Chen , "open list:USB SUBSYSTEM" , open list , kernel Subject: Re: [PATCH] usb: core: hcd: fix bug: application of sizeof to pointer Message-ID: References: <20211207135401.5507-1-guozhengkui@vivo.com> <14d2ddb6-4a4a-bb4d-48bf-4847445d6199@vivo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <14d2ddb6-4a4a-bb4d-48bf-4847445d6199@vivo.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 08, 2021 at 11:00:41AM +0800, Guo Zhengkui wrote: > On 2021/12/8 6:21, Alan Stern wrote: > > On Tue, Dec 07, 2021 at 03:40:37PM +0100, Greg Kroah-Hartman wrote: > > > On Tue, Dec 07, 2021 at 09:53:47PM +0800, Guo Zhengkui wrote: > > > > Fix following error: > > > > ./drivers/usb/core/hcd.c:1284:38-44: ERROR: > > > > application of sizeof to pointer. > > > > > > What generated this error? > > > > > > > > > > > Use sizeof(*vaddr) instead. > > > > > > > > Signed-off-by: Guo Zhengkui > > > > --- > > > > drivers/usb/core/hcd.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c > > > > index 4d326ee12c36..996d5273cf60 100644 > > > > --- a/drivers/usb/core/hcd.c > > > > +++ b/drivers/usb/core/hcd.c > > > > @@ -1281,7 +1281,7 @@ static int hcd_alloc_coherent(struct usb_bus *bus, > > > > return -EFAULT; > > > > } > > > > - vaddr = hcd_buffer_alloc(bus, size + sizeof(vaddr), > > > > + vaddr = hcd_buffer_alloc(bus, size + sizeof(*vaddr), > > > > > > I think you just broke the code. > > > > > > Look at this closer and see what the function is doing with this buffer > > > and if you still think your patch is correct, please rewrite the > > > changelog text to explain why it is so (hint, just using the output of > > > coccinelle isn't ok.) > > > > Sorry for my carelessness. It should be sizeof(vaddr). > > > Although the patch is definitely wrong, the code could stand to be > > improved. The value stored at the end of the buffer is *vaddr_handle > > converted to an unsigned long, but the space reserved for this value is > > sizeof(vaddr) -- which doesn't make much sense since vaddr is a pointer > > to unsigned char. The code implicitly relies on the fact that unsigned > > long takes up the same amount of space as a pointer. > > > > Readers wouldn't have to stop and figure this out if the amount of > > reserved space was simply set to sizeof(unsigned long) rather than > > sizeof(vaddr). > > OK, I will commit another patch to fix this problem. Do you mind I add a > "Suggested-by" tag of your name (Alan Stern) in this new patch? That's fine. Alan Stern