Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp476958ybh; Mon, 20 Jul 2020 23:20:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMaDLVbnGP6GrUEWNAs9f13/9sHuo99lb3DG0sxOiH4DAGd/RFmDwtIFhqC36Se2Da9fjx X-Received: by 2002:a17:906:748:: with SMTP id z8mr24658885ejb.257.1595312446750; Mon, 20 Jul 2020 23:20:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595312446; cv=none; d=google.com; s=arc-20160816; b=HV/mzNDR55z0YQKoT6QdvuvvIOovU9o23Xxp8GX3YYocw4i47+xuGp1SKbjbU+D+NQ TmhUej4Fq/IffpYwAmyDG3l8o50FxaE1ZwT/kJNiRF6+4uRlVkRDx1iPv9+mrqhxSlML NmrdmJozLli/443k3gcYKvNf6Bwn4hSHtkFTb+/7kJJ3wV69j7lk1hEhalADldS9azbf t5KIdnTZfzptBoQuYk9e2RzzNPIEHFt8jD4ljnfePIrZVPX81ldz/dYRZZVqnp/qrjK7 rXdmg/KSb6/6LKIUPnzLDLKZ6/6GIzU/39gcqobRpdjnF3oSfB6czeBFHBTDSYzC1rFT QBdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=k72+sPERZ6swjjGWELY1PUSa54/Fs5E+CfkoR0k6Dqs=; b=HExi1M/1d99dMqcTIiJq5J4GlU+EV9EXZ27zWL2Xis2kEQEsNfW/Vv0MJD0ERffOiA PHBUVW6FmQEMLjgA7SPqXOMaBFrcn+7/05+VhqbsSvpoByLLwD5UFdTVZOz4mEG/fABD 8dmh4Sy6vlG3dSMv8cNPXM6hahpTSQGAuGv2uFgd7HjxhV2KudNHnHAAseDuHAhUCRrq Qa37pbOxtjDBsoYCGdjQcCZIr+1W2nWdTXRfAdw5xYmemopmSwEj6mWiHmyyJZ8VYWSI 5REdSGPHEoQRlL5GH2XRvuURPTrJGIKebaB5jTDWTxKYfKzrLOK9kYqhUfLSRQeQPYzk Rpjw== ARC-Authentication-Results: i=1; mx.google.com; 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 l10si11439811ejh.673.2020.07.20.23.20.24; Mon, 20 Jul 2020 23:20:46 -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; 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 S1726737AbgGUGR6 (ORCPT + 99 others); Tue, 21 Jul 2020 02:17:58 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:8338 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725294AbgGUGR6 (ORCPT ); Tue, 21 Jul 2020 02:17:58 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id CD319428CB13F7977094; Tue, 21 Jul 2020 14:17:50 +0800 (CST) Received: from [127.0.0.1] (10.174.178.16) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Tue, 21 Jul 2020 14:17:40 +0800 Subject: Re: [PATCH] ipmi/watchdog: add missing newlines when printing parameters by sysfs To: Joe Perches , CC: , , , , References: <1595210605-27888-1-git-send-email-wangxiongfeng2@huawei.com> <20200720195234.GC2952@minyard.net> <908fcbf2-efbb-b3f4-0666-2da79fbe99c4@huawei.com> From: Xiongfeng Wang Message-ID: <70f4a8b9-1410-a32d-dfaa-4cb5d3cade10@huawei.com> Date: Tue, 21 Jul 2020 14:17:40 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.178.16] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/7/21 10:00, Joe Perches wrote: > On Tue, 2020-07-21 at 09:20 +0800, Xiongfeng Wang wrote: >> On 2020/7/21 3:52, Corey Minyard wrote: >>> On Mon, Jul 20, 2020 at 10:03:25AM +0800, Xiongfeng Wang wrote: >>>> When I cat some ipmi_watchdog parameters by sysfs, it displays as >>>> follows. It's better to add a newline for easy reading. > [] >>>> diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c > [] >>>> @@ -232,12 +232,16 @@ static int set_param_str(const char *val, const struct kernel_param *kp) >>>> static int get_param_str(char *buffer, const struct kernel_param *kp) >>>> { >>>> action_fn fn = (action_fn) kp->arg; >>>> - int rv; >>>> + int rv, len; >>>> >>>> rv = fn(NULL, buffer); >>>> if (rv) >>>> return rv; >>>> - return strlen(buffer); >>>> + >>>> + len = strlen(buffer); >>>> + len += sprintf(buffer + len, "\n"); >>> >>> sprintf is kind of overkill to stick a \n on the end of a line. How >>> about: >>> >>> buffer[len++] = '\n'; >>> >>> Since you are returning the length, you shouldn't need to nil terminate >>> the string. > > You never quite know for sure so I suggest making > the string null terminated just in case. > > i.e.: > > buffer[len++] = '\n'; > buffer[len] = 0; > Thanks for your advice. I will change it in the next version. Thanks, Xiongfeng > > > . >