Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2265545ybb; Sat, 21 Mar 2020 17:26:11 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvPianFg4gFyuGmkhtEHNbAsqUBXwB8Lh5uMksmTvsP9fI46y4B2MmSB8Bxvb2VGdt2ks4d X-Received: by 2002:a9d:66d5:: with SMTP id t21mr12764603otm.284.1584836771065; Sat, 21 Mar 2020 17:26:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584836771; cv=none; d=google.com; s=arc-20160816; b=gUtA9ee5+boLT8s28NBVYCH68rJdDDQC97uP/CzXRuWkdbKNnaah1Sc0I8UR0xM87e Jo9dyVRAdYaEVPCvwBLDLcTmvOhaor7W0NZ3PdoywnCC2uolaYwx6uQZ03uQAiHzlsfH hLmZwczaZ9I5dKyb3+jKrOK/KxVbZ1j2EdUyl7Dv/4b+6JvOQRD9XA4wdjqhIof031g9 c8/4K4M3GjL0iw0WbfNuOpgE3RpTPFsUOR1+ZXn3wzIGmyV1kCAU+5JCX7ZLW29QCwRF /fjrNf1RPj4+Ji+5MGp+S3BmDclRWgxH9cdGqFe0aSogwDKPdxm+K0RJG34bsrbRyEyu lguQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=yYZ59g3ZqxLhdYgqTzNzt4bqT/ILBYpVRPmnAzH5Vvc=; b=clOQneFYrmu3EnMj3rmnvqqsRWI84LaOL4fqMGvZ5epPercbEnIY/aYm1oEs5CRmwK UR9mmHghXd5fPRvchWRw7mhKdkUELvN/3vk4h5ZFzGVwWSXpO9M+A3G7bsZGL9W/c1gD 0Hv/7nhKB6HxOuAcx6B1rv2AozaDBKKHk/76mWm9CxI4zaqT3sJra0vdbHZUv9JHclEi 7cUaHDYRO+8Y7NBIN76/AvHglExB5x5nZ9qbr3GmTtoqF2nwJ0LDv+NMwcZhnCohDzW8 3BnuVN7d267Vby18etGScqQ8XXKdJa6xgR5MmpkwLJsDhKjwVJkafKVxTHSyOvxkniua Cb5A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v22si5142087oic.271.2020.03.21.17.25.58; Sat, 21 Mar 2020 17:26:11 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728118AbgCVAZn (ORCPT + 99 others); Sat, 21 Mar 2020 20:25:43 -0400 Received: from mga14.intel.com ([192.55.52.115]:30447 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727296AbgCVAZn (ORCPT ); Sat, 21 Mar 2020 20:25:43 -0400 IronPort-SDR: LU5tnGu79NI8ftd9DyBlDFfWc9lECniFP14v4zMKMHwf7tUaqe4yThJJpwniz3gXhdh+Z8by09 j620MPSDGT7w== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2020 17:25:43 -0700 IronPort-SDR: xxcblHMX2RBUykp4thoYSybBcZ9e/GoEScu8af4cI/GdBdJGgLUMtPkHogh2/F3OPZGlhfYb+L wKTOFtak/WxA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,290,1580803200"; d="scan'208";a="325223523" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga001.jf.intel.com with ESMTP; 21 Mar 2020 17:25:40 -0700 Received: from andy by smile with local (Exim 4.93) (envelope-from ) id 1jFoQw-00BrDM-F8; Sun, 22 Mar 2020 02:25:42 +0200 Date: Sun, 22 Mar 2020 02:25:42 +0200 From: Andy Shevchenko To: Rohit Sarkar 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 Message-ID: <20200322002542.GA2826015@smile.fi.intel.com> References: <5e723666.1c69fb81.3545b.79c3@mx.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5e723666.1c69fb81.3545b.79c3@mx.google.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? -- With Best Regards, Andy Shevchenko