Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2454211ybb; Sat, 21 Mar 2020 23:13:11 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuTME3SQIT/jDPEBVC2cQEBC2Z0AC4YQr9Ko+UHDlqFPuuEYyvhhhNc7BZXY0jtD/wDiwrl X-Received: by 2002:a05:6830:1aca:: with SMTP id r10mr12395191otc.330.1584857590913; Sat, 21 Mar 2020 23:13:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584857590; cv=none; d=google.com; s=arc-20160816; b=ZuWlIh4t60FZkH2cTKrkpMUUBmM2yNou/4UCWhq93OBo/9A3CbRINKMePgYwrd+zjx i0zUNHL/KUxLf4hCNdxG4kSxLAFu2eoZqMNx6gT1e5zaLxbw4X41GgwBC1EyAfV9lCNj u1zobzTtkNd9pO75dFxkHND/0hsbHei/WwPGPpwJMFZcg52tRbPyN541GOY1Q3Oby4Vo 6EcBQNavM1WPAFzuf2h+tX2S1TvNxxtm+BbQJxAoFqM31NSIp0NQYRS+yznfzYAyI3Jp HJ1qhJmfnUcGxyj7i0t2Ub2+TuITlSk8zFatB+jbpxApajLTywsQ1QD+WyGNFj+AXcpC puzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:subject:cc:to:from:date :message-id:dkim-signature; bh=OlTTwgDJDrxhOFNzpLQTgXtTgLH4e4DZxu3thtRL82o=; b=uBD7OWqxreAq/vrtJMadjG1i8NO+RnAIrUjBjhzPTT++DlbLLWqu08Cl2BGOJ+AM6v qJ9p3zulhn04e2BpHwDIPZmDrICJVTTugLMSL73UbnO0vMhMVjrfR/4cgYKfIWYzM/Gr AbIHe5trx+HLfrKaMJOvXmlGUenMjL2SR+J7ckoEFzLdbTTtyRCaTh48/8YRplqXN8UZ 9jCi80vLAiUjIyL4jAQfy2mkFP+ZGpUeTSTeKjf6zhRv3UJvqTIYM5RS4SFF4AjMWNnH 8uhchWwOgq6TzDqX0Ifydg4UPtLKm9tuPXfKb3XqNO4uiSJK3xvTw3Dq0s1bEECNxd6i T/RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=h337aAfE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l18si5066921otb.312.2020.03.21.23.12.36; Sat, 21 Mar 2020 23:13:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=h337aAfE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726728AbgCVGLK (ORCPT + 99 others); Sun, 22 Mar 2020 02:11:10 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:45240 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725881AbgCVGLJ (ORCPT ); Sun, 22 Mar 2020 02:11:09 -0400 Received: by mail-pf1-f196.google.com with SMTP id j10so5718639pfi.12; Sat, 21 Mar 2020 23:11:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:date:from:to:cc:subject:references:mime-version :content-disposition:in-reply-to:user-agent; bh=OlTTwgDJDrxhOFNzpLQTgXtTgLH4e4DZxu3thtRL82o=; b=h337aAfEFa9h2tcpJIXUoh+RHQPy44foiVQQyVLR5FcC2ClOiZBE8d1SrnX3yQWwaX tgz+qxMiyaj209JhBonSMiwiDsCdTl0lfOcdfuEThU4q+g0Rhh8/myDM0umodKqMve+Z nI3gbp7zJKPBmdnCcFDSyPP/GIdv2znD84wIAGS2Xb6QzJXvNZa1VIPs+F9I0i339ZOb 47NcAJHggaHFjOYwXQqxMW/3l/NYmbRhz+JA6ERCM3sgXb2wg31dlWjaYrzTO7QmWTNj r7EIR+1ZeNiAfV2PE8b56AhkM4pwyiRt6VNSJXDg8cri+CdT0Td3kvXJ+YB4zQ+YQ78K KTSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:date:from:to:cc:subject:references :mime-version:content-disposition:in-reply-to:user-agent; bh=OlTTwgDJDrxhOFNzpLQTgXtTgLH4e4DZxu3thtRL82o=; b=Nh8/nRCZ5Jw95QSiaUPu3E6ZzvkLZBJ1FwVHKZsxy22FpNKZnzsK1rSxm2V9loATCl Wvv5clTZXCwb1UtOt3dDfM8HojUxXN9VqHtVuH2svP35oJ+eHWl1XkwM8UR8hWhfAnsG 720hLxPH4XhP4es3WNoJoYGzzZxMlCaK14AS5C/84dio68naVSWzkpxlaEtSpvQQONB7 a3CIa+lKfteePhRbyA1eg0i+aZQjW9Q89TiTDvwwg9G/PdwwT1lenu64p/rIF3pdB4fv xJOz4FDipCEJXYitpXUz1x/XSzcLlRXe6c5Qe6Rj3fp/4YDxm6vVSSeWXtjbMIaBFxJ3 meZQ== X-Gm-Message-State: ANhLgQ3J5uDKBYyYOerSxMjiCaKkMddO6cOl2BmZ0AS+Y26VLFmiLrt9 WN7fipLPRstY9GLYA8JTpe/FO1y9kEY= X-Received: by 2002:a63:5011:: with SMTP id e17mr16250248pgb.338.1584857466789; Sat, 21 Mar 2020 23:11:06 -0700 (PDT) Received: from SARKAR ([49.207.56.153]) by smtp.gmail.com with ESMTPSA id w4sm6744586pfc.57.2020.03.21.23.11.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 23:11:06 -0700 (PDT) Message-ID: <5e77017a.1c69fb81.dc341.8ab9@mx.google.com> X-Google-Original-Message-ID: <20200322061102.GA17797@rohitsarkar5398@gmail.com> Date: Sun, 22 Mar 2020 11:41:02 +0530 From: Rohit Sarkar To: Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, jic23@kernel.org, dragos.bogdan@analog.com, Lars-Peter Clausen , Michael Hennerich , Stefan Popa , knaack.h@gmx.de, pmeerw@pmeerw.net Subject: Re: [PATCH] iio: gyro: adis16136: use scnprintf instead of snprintf References: <5e723666.1c69fb81.3545b.79c3@mx.google.com> <20200322002542.GA2826015@smile.fi.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200322002542.GA2826015@smile.fi.intel.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 22, 2020 at 02:25:42AM +0200, Andy Shevchenko wrote: > On Wed, Mar 18, 2020 at 08:25:22PM +0530, Rohit Sarkar wrote: > > scnprintf returns the actual number of bytes written into the buffer as > > opposed to snprintf which returns the number of bytes that would have > > been written if the buffer was big enough. Using the output of snprintf > > may lead to difficult to detect bugs. > > Nice. Have you investigate the code? > > > @@ -96,7 +96,7 @@ static ssize_t adis16136_show_serial(struct file *file, > > if (ret) > > return ret; > > > > - len = snprintf(buf, sizeof(buf), "%.4x%.4x%.4x-%.4x\n", lot1, lot2, > > + len = scnprintf(buf, sizeof(buf), "%.4x%.4x%.4x-%.4x\n", lot1, lot2, > > lot3, serial); > > > > return simple_read_from_buffer(userbuf, count, ppos, buf, len); > > The buffer size is 20, the pattern size I count to 19. Do you think snprintf() > can fail? That might be the case, but IMO using scnprintf can be considered as a best practice. There is no overhead with this change and further if the pattern is changed by someone in the future they might overlook the buffersize Thanks, Rohit > -- > With Best Regards, > Andy Shevchenko > >