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=-9.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 5ED93C46466 for ; Mon, 5 Oct 2020 04:19:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 27CD2207C4 for ; Mon, 5 Oct 2020 04:19:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725863AbgJEETT (ORCPT ); Mon, 5 Oct 2020 00:19:19 -0400 Received: from smtprelay0195.hostedemail.com ([216.40.44.195]:47212 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725844AbgJEETS (ORCPT ); Mon, 5 Oct 2020 00:19:18 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay06.hostedemail.com (Postfix) with ESMTP id 9D24518224D61; Mon, 5 Oct 2020 04:19:17 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: fold51_2101521271bb X-Filterd-Recvd-Size: 2681 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf10.hostedemail.com (Postfix) with ESMTPA; Mon, 5 Oct 2020 04:19:16 +0000 (UTC) Message-ID: Subject: Re: [PATCH] test_power: add missing newlines when printing parameters by sysfs From: Joe Perches To: "Harley A.W. Lorenzo" , Sebastian Reichel Cc: "linux-pm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "wangxiongfeng2@huawei.com" Date: Sun, 04 Oct 2020 21:19:15 -0700 In-Reply-To: <1g3ecQ7VLlrgKOSHr6teWgw9xcmVVQx1bFp2KpJD7y35lZpaC8ONb-jrPKapmFttEwVg2uhDwmv6mug9z5-GVZbqPbkOjcqjrSHtaW-k6ts=@protonmail.com> References: <1599199798-27804-1-git-send-email-wangxiongfeng2@huawei.com> <20201003212336.5et7erdf6fihqscu@earth.universe> <472008b94f4b20915425db4714fdb505cb0cbe5a.camel@perches.com> <20201003215029.jsugcgpgrmcmydr3@earth.universe> <9822843f764520e1076a92fd9120294aa393a085.camel@perches.com> <20201004221645.nyaf7jhur4jixo6n@earth.universe> <1g3ecQ7VLlrgKOSHr6teWgw9xcmVVQx1bFp2KpJD7y35lZpaC8ONb-jrPKapmFttEwVg2uhDwmv6mug9z5-GVZbqPbkOjcqjrSHtaW-k6ts=@protonmail.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.36.4-0ubuntu1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2020-10-05 at 01:30 +0000, Harley A.W. Lorenzo wrote: > Here is the updated patch using sprintf, diffing from the original patch by Xiongfeng Wang. > > [PATCH] test_power: revise parameter printing to use sprintf > > Signed-off-by: Harley A.W. Lorenzo > Suggested-by: Joe Perches I did not suggest this. > diff --git a/drivers/power/supply/test_power.c b/drivers/power/supply/test_power.c [] > @@ -352,8 +352,8 @@ static int param_set_ac_online(const char *key, const struct kernel_param *kp) > > static int param_get_ac_online(char *buffer, const struct kernel_param *kp) > {. > - strcpy(buffer, map_get_key(map_ac_online, ac_online, "unknown")); > - strcat(buffer, "\n"); > + char const *out = map_get_key(map_ac_online, ac_online, "unknown"); > + sprintf(buffer, "%s\n", out); > return strlen(buffer); > } No temporary is necessary nor is strlen as that's the same as the return from sprintf. All of these should be similar to: static int param_get_ac_online(char *buffer, const struct kernel_param *kp) { return sprintf(buffer, "%s\n", map_get_key(map_ac_online, ac_online, "unknown")); }