From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FE3AC4332E for ; Sun, 22 Mar 2020 00:25:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5010B20782 for ; Sun, 22 Mar 2020 00:25:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727533AbgCVAZn (ORCPT ); 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-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@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