Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1512364rdd; Thu, 11 Jan 2024 01:06:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1gQrwS5ZfGP89nsWsa1o4Y4xo+AZTdSHot/T/2eY4bFgPNdrxrLfpGFpxVJLNW0W/9BaO X-Received: by 2002:a05:620a:b03:b0:783:3889:491c with SMTP id t3-20020a05620a0b0300b007833889491cmr1067786qkg.13.1704963998384; Thu, 11 Jan 2024 01:06:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704963998; cv=none; d=google.com; s=arc-20160816; b=VWbIdf4tt+qobmP/9gbr4xJXVcrGiSwmaYmFUhRzNBFpKRKxVG74+j8N6tW1+Ke4gW 3ZYfApe6jTZgeprvXzmreF98eLzCm6szY8xRRGo8G2y9itWezGqQCML47iiic8J/2wSs vqNzEMdrfVjg3b22DM+kgQpOrpZDTyi8Sc3bDQFpQIgiKZMDMYFwZ29gAo6+CgGr90pl 5SIRSEqJIxJMDwszt7zKewW2X/M2L+nHBQhJhifnlwOnVXd4MbOwOropck2uViZNArjt 0TDB4F1Q11yDgc48U66qw9IgKdlSrzHzHXJKhdEQm2n6JxjHW/AZBblibB/pPFjR87uL 0ZwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence; bh=B7MxYqmNVeVBj/KRUwDapZFmGXZW/nJpRqUsjEmlW9I=; fh=fA7SGnc0Lkh0maC27R2LHc2e4T+XoP9QKZT1BODkLF0=; b=kLFa4fgtUZEXUSF68NT/WptcwJ6WR9nlmyhnxZge7EUkDabjD77V98Y8nAi5Hmw8pm YcK5PtJniQQ8u2lQqibGeoT3y1GvTF2eYml+JTRJ/3O3tQb6s5BV9SxzjsjZjQX2muML qCRJAvAbeaJ590o2Pu61ldCIWnAvasgdLg5pOFsZ9b3MXeaU0eYtSzfh0910r6qkF/2k DjUnDrJH16TKMvd9hC7bmgFIjJTm2uStzIRwv0x48cHIHfbKryUDmGgNgjhP3EsdA5o8 +QrvnPLqvX7dvQKarzd7L25dpOBX2siy7BEo84IlrMFVGIkNqKD6N1HZ6lvSM/wZ/5kO 0WGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-23289-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23289-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f28-20020a05620a20dc00b0078324656c30si507448qka.540.2024.01.11.01.06.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 01:06:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23289-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-23289-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23289-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D6AD61C25AF5 for ; Thu, 11 Jan 2024 09:06:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D3764101C5; Thu, 11 Jan 2024 09:05:24 +0000 (UTC) Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AAF2DF6E; Thu, 11 Jan 2024 09:05:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-5edfcba97e3so53639907b3.2; Thu, 11 Jan 2024 01:05:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704963921; x=1705568721; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iR6KU/zGe5ub/62SWQbwkfMRKXXvW7W7wYmrGRm2qBE=; b=gYXHOGG3tkCqkbtLdpX4dcQklepvn6Bepm9GYZTcJTxNvEeQ8Dms0wlGMgwlboBswh +GroZYRA2OOcyGJ/ERvOqr98ZXKTcTIG7vhCEDuOia7AVFDQPkaWJFimADwr4TvwMO2C pdEufVdFJkm88EEDfREcX7cn1zDdSDrqLWBY3crbirO2LDbwDfO3d5fKv1k15DYhL0ft LvWFj2vxLyeHNwj5kK6sZbnW//FjQ7uideRCaKgURGDqEFFiqHj5oqBgdPAEV3e2ioGg aVknLTI76MlZI7iwP5haxNJOZajuPO3TFQ9NBQZQztNUni+grig9V3HPd++tDsjWWZSC fI/g== X-Gm-Message-State: AOJu0Yx2JFAzmn393PWiluols84mZEF/VuNNR3jGYyq/IdByCoIvfkeq XWPCsuv05VeebxarblzuplOAwmH9sGcFHw== X-Received: by 2002:a05:690c:fd1:b0:5d7:1940:f3d2 with SMTP id dg17-20020a05690c0fd100b005d71940f3d2mr296288ywb.58.1704963920831; Thu, 11 Jan 2024 01:05:20 -0800 (PST) Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com. [209.85.219.172]) by smtp.gmail.com with ESMTPSA id u80-20020a818453000000b005e7467eaa43sm254600ywf.32.2024.01.11.01.05.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Jan 2024 01:05:20 -0800 (PST) Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-dbf2b5556f9so1367952276.2; Thu, 11 Jan 2024 01:05:20 -0800 (PST) X-Received: by 2002:a5b:5d2:0:b0:dbf:196c:b615 with SMTP id w18-20020a5b05d2000000b00dbf196cb615mr950823ybp.0.1704963919994; Thu, 11 Jan 2024 01:05:19 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240110222210.193479-1-prabhakar.mahadev-lad.rj@bp.renesas.com> In-Reply-To: <20240110222210.193479-1-prabhakar.mahadev-lad.rj@bp.renesas.com> From: Geert Uytterhoeven Date: Thu, 11 Jan 2024 10:05:00 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] dmaengine: usb-dmac: Avoid format-overflow warning To: Prabhakar Cc: Vinod Koul , =?UTF-8?Q?Uwe_Kleine=2DK=C3=B6nig?= , Tudor Ambarus , Kees Cook , dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , Lad Prabhakar Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Prabhakar, On Wed, Jan 10, 2024 at 11:23=E2=80=AFPM Prabhakar wrote: > From: Lad Prabhakar > > gcc points out that the fix-byte buffer might be too small: > drivers/dma/sh/usb-dmac.c: In function 'usb_dmac_probe': > drivers/dma/sh/usb-dmac.c:720:34: warning: '%u' directive writing between= 1 and 10 bytes into a region of size 3 [-Wformat-overflow=3D] > 720 | sprintf(pdev_irqname, "ch%u", index); > | ^~ > In function 'usb_dmac_chan_probe', > inlined from 'usb_dmac_probe' at drivers/dma/sh/usb-dmac.c:814:9: > drivers/dma/sh/usb-dmac.c:720:31: note: directive argument in the range [= 0, 4294967294] > 720 | sprintf(pdev_irqname, "ch%u", index); > | ^~~~~~ > drivers/dma/sh/usb-dmac.c:720:9: note: 'sprintf' output between 4 and 13 = bytes into a destination of size 5 > 720 | sprintf(pdev_irqname, "ch%u", index); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Maximum number of channels for USB-DMAC as per the driver is 1-99 so use > u8 instead of unsigned int/int for DMAC channel indexing and make the > pdev_irqname string long enough to avoid the warning. > > While at it use scnprintf() instead of sprintf() to make the code more > robust. > > Signed-off-by: Lad Prabhakar Reviewed-by: Geert Uytterhoeven One nit below. > --- a/drivers/dma/sh/usb-dmac.c > +++ b/drivers/dma/sh/usb-dmac.c > @@ -768,8 +768,8 @@ static int usb_dmac_probe(struct platform_device *pde= v) > const enum dma_slave_buswidth widths =3D USB_DMAC_SLAVE_BUSWIDTH; > struct dma_device *engine; > struct usb_dmac *dmac; > - unsigned int i; > int ret; > + u8 i; Personally, I'm not much a fan of making loop counters smaller than (unsigned) int. If you do go this way, there are more loops over all channels still using int. Gr{oetje,eeting}s, Geert --=20 Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k= org In personal conversations with technical people, I call myself a hacker. Bu= t when I'm talking to journalists I just say "programmer" or something like t= hat. -- Linus Torvalds