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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1C31C04A95 for ; Wed, 28 Sep 2022 23:10:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234124AbiI1XKt convert rfc822-to-8bit (ORCPT ); Wed, 28 Sep 2022 19:10:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233770AbiI1XKs (ORCPT ); Wed, 28 Sep 2022 19:10:48 -0400 Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21D694D4EF for ; Wed, 28 Sep 2022 16:10:46 -0700 (PDT) Received: from omf15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 42F1F810C9; Wed, 28 Sep 2022 23:04:10 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf15.hostedemail.com (Postfix) with ESMTPA id C450B1A; Wed, 28 Sep 2022 23:04:01 +0000 (UTC) Message-ID: <46a600465f08edbda7d413f6dd0b1b1edd57cfa4.camel@perches.com> Subject: Re: [PATCH 3/7] s390/qeth: Convert snprintf() to scnprintf() From: Joe Perches To: Alexandra Winter , Jules Irenge , borntraeger@linux.ibm.com Cc: svens@linux.ibm.com, linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, agordeev@linux.ibm.com Date: Wed, 28 Sep 2022 16:04:07 -0700 In-Reply-To: References: <5138b5a347b79a5f35b75d0babf5f41dbace879a.camel@perches.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Stat-Signature: 77c4p56xgruk3p35i1uacr4yaetb35qj X-Rspamd-Server: rspamout01 X-Rspamd-Queue-Id: C450B1A X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX18eEEanHqR4OnqcwMowgOsKUxuaq/Kzxbo= X-HE-Tag: 1664406241-228711 Precedence: bulk List-ID: X-Mailing-List: linux-s390@vger.kernel.org On Wed, 2022-09-28 at 10:24 +0200, Alexandra Winter wrote: > On 27.09.22 16:27, Joe Perches wrote: > > On Mon, 2022-09-26 at 19:42 +0100, Jules Irenge wrote: > > > Coccinnelle reports a warning > > > Warning: Use scnprintf or sprintf > > > Adding to that, there has been a slow migration from snprintf to scnprintf. > > > This LWN article explains the rationale for this change > > > https: //lwn.net/Articles/69419/ > > > Ie. snprintf() returns what *would* be the resulting length, > > > while scnprintf() returns the actual length. > > [] > > > diff --git a/drivers/s390/net/qeth_core_sys.c b/drivers/s390/net/qeth_core_sys.c > > [] > > > @@ -500,9 +500,9 @@ static ssize_t qeth_hw_trap_show(struct device *dev, > > > struct qeth_card *card = dev_get_drvdata(dev); > > > > > > if (card->info.hwtrap) > > > - return snprintf(buf, 5, "arm\n"); > > > + return scnprintf(buf, 5, "arm\n"); > > > else > > > - return snprintf(buf, 8, "disarm\n"); > > > + return scnprintf(buf, 8, "disarm\n"); > > > } > > > > Use sysfs_emit instead. > > > > Thank you Joe, that sounds like the best way to handle this. > I propose that I take this onto my ToDo list and test it in the s390 environment. > I will add > Reported-by: Jules Irenge > Suggested-by: Joe Perches > Thanks. btw: I was careless when I wrote one section of the proposed patch. In this patch block, @@ -467,28 +478,31 @@ static ssize_t qeth_dev_switch_attrs_show(struct device *dev, The last line + return sysfs_emit_at(buf, len, "\n"); is not correct It needs to be changed to: len += sysfs_emit_at(buf, len, "\n"); return len;