Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1872507ybt; Sun, 21 Jun 2020 02:00:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAS/r/0NBHipjIo7IeUZPVkEMSVfIQAbWhb3hJJdabd7d9bJK2tmxtsujmdrJvuFmRkqvu X-Received: by 2002:a17:906:a387:: with SMTP id k7mr11589940ejz.408.1592730045802; Sun, 21 Jun 2020 02:00:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592730045; cv=none; d=google.com; s=arc-20160816; b=L5BnMxlbNvFRQJcNUkmE/N8wX2DWUSHIRTIwvjR2+WWOPIQeZpy/VX4SMGPbiWaOPe iUQ7DqKaSJU6yXhrGEAxWaqQuaBtH34x6mYBuxyQqgpK89PRV/uyPGKsI8Jzb9Twz0GI /J0P0u9FeJdEYULrq0UzUj/MbmY/2GRIKksEm+/4Ibc2M3u8YjRA2YsDjsJFch0L/X1O jq889A0rLJgR6uYaFqz1eui3k6mntAsWgrJOctV/IsXp/XMpmjpyglIK9LKFuYTIpbY2 xxsVuYLoRhEd2KqbgKVYz9wrVSNwvXsmR2H0QJsGFLUWOmNQi3ZB4FZD81a8JgJ3p68d LuHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=tP86EHbJ6lHp1EZQefhq8sugOUyiJQn2ShuBojFHUmk=; b=DibD7xpfnzQYUZJFdyg0NynGbgq1HlvoIGMvDpBeZA06zUq6hgIf6cUQygc8AnW/72 92FiGDXc5FwEv5WPiEmcsjoxKZI65OXXYINlZ8jTruO7hOYVYnRt3KjrZO3G59OdFYf8 RVcmBpIuEnaiaC5RnPum3xNLyiVZv1hqgRVq2/HQRXlmf6UvRGrpyrIt96p28qWwJ7go vM76ZtWLLJ+W69o1YPEs+mLb+YqLzHFcwIGLc8nEb3P9wAPsu9iaiczpvlWAl97S9cgs b976XZf2vOtslyN/NearXtrRtKlyuD0MYvIKzmjRC6+znCU4Ff86L3VKzSbaifnbnKFl Rd6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sL36EOLJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id zo8si6970935ejb.156.2020.06.21.02.00.06; Sun, 21 Jun 2020 02:00:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sL36EOLJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729563AbgFUI5E (ORCPT + 99 others); Sun, 21 Jun 2020 04:57:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:44280 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729535AbgFUI5E (ORCPT ); Sun, 21 Jun 2020 04:57:04 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 90D9F24873; Sun, 21 Jun 2020 08:57:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592729824; bh=aNokLRmz+McR+JnvgxLD0kUt51Spv/CfHrKAYcpobt8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=sL36EOLJPpclspiw1an0FN767mLQWip7XGOgNOws60isiEjuBTdYI1zxVatrnsnhT NWdG64raeVKSkEcPuAYLVENTbUl1WoldCUdu/e6VcFh/DwID7TIADItORexhXo5utk SXDLl0r1U9J2hVw07KwWew1hb5siAJahlbx0SxpU= Date: Sun, 21 Jun 2020 10:56:56 +0200 From: Greg Kroah-Hartman To: Denis Efremov Cc: "Rafael J. Wysocki" , linux-kernel@vger.kernel.org Subject: Re: [PATCH] driver core: Use scnprintf() instead of snprintf() in device show functions Message-ID: <20200621085656.GA95977@kroah.com> References: <20200620150529.18678-1-efremov@linux.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200620150529.18678-1-efremov@linux.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jun 20, 2020 at 06:05:29PM +0300, Denis Efremov wrote: > >From Documentation/filesystems/sysfs.txt: > - show() must not use snprintf() when formatting the value to be > returned to user space. If you can guarantee that an overflow > will never happen you can use sprintf() otherwise you must use > scnprintf(). > > The reason is that snprintf() returns the length the resulting string > would be, assuming the data will fit into the destination array. > scnprintf() returns the length of the string actually created in buf. > > device_show_{ulong,int,bool}() functions are reference implementation > and should respect the kernel documentation. Ok, but you are not following that documentation below, why not? > > Signed-off-by: Denis Efremov > --- > > Actually, I don't know why snprintf() is used here initially. It looks > safe to use sprintf(). > > drivers/base/core.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/base/core.c b/drivers/base/core.c > index 67d39a90b45c..2815deb511fc 100644 > --- a/drivers/base/core.c > +++ b/drivers/base/core.c > @@ -1472,7 +1472,7 @@ ssize_t device_show_ulong(struct device *dev, > char *buf) > { > struct dev_ext_attribute *ea = to_ext_attr(attr); > - return snprintf(buf, PAGE_SIZE, "%lx\n", *(unsigned long *)(ea->var)); > + return scnprintf(buf, PAGE_SIZE, "%lx\n", *(unsigned long *)(ea->var)); As the documentation states, these should just be sprintf(), if you really want to change these. As-is, these are also ok, there is no need to change. thanks, greg k-h