Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp344537pxb; Thu, 21 Oct 2021 00:09:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXd/qVl0xHOkqImoMhKisNmTFc4SSIvKsRK9y51NZyW/gI3B00NMRYj/GIELUwO6dLUneo X-Received: by 2002:a05:6a00:1748:b0:44c:ca52:b261 with SMTP id j8-20020a056a00174800b0044cca52b261mr3848389pfc.17.1634800196882; Thu, 21 Oct 2021 00:09:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634800196; cv=none; d=google.com; s=arc-20160816; b=yFJmwSmvSzx9XN4S1KMaYnH9HfRbTRXoFvBT/gXbBEUJx6p7l9P35uLCKGeWHvvCkH JWisNezW75rcesKjleQHlvDBDUSaRmIsPhVgDO/vGMapBdWWCtT9Fd03N2FsSJyubzn1 RmC68I+8nFQ7DU67EyCCY6rC1ZmbsOjhGyn8eF2W597rXngTQTSX/lMkTvuCES3HWWmA inWxu5hU+UHw04hjOvUhl3mmFzjbUochkbSLYU15C7Wo5uqvxkEesLND4FkLMyrTWuO6 i/BITjXnUX/A7z2vVKV+iP2GOg147qXoksnc/n3Cu418F9Vtw9Kle9BUWgeitBAr2hZy UBpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=P5rjF3C7PwJeQHjAo3nezeQr27ApCly/4GyS8BifxYY=; b=YK97MRAIztzXcMcLmn+MZIF/Iyy/FFS1NlTPfcJheOQyjP39ooTD/RFQlSTlkSEJrY adQFnHw+/WNhg8ylus2leEEflvxFDHrxDoZrdJnA7166Bn5tyMM+bKrdYRkYFnSj241x h598XGzvZ22moYxrvjGj8ncqbpuqhtJppTgr68CDF6CJxZPqwIUV4YkQSxduXknjmS8B /Tw6orGo6s/nIOTZVAArMGn9OB1A2R7EJ29C7Uep3WvuLaMjOqWfU5OYxramnxcBvT3w xNuiZOwO91R7pE/b4LczgD88LNRD60czwp/XcOWLmcqeNZ3f8CYRaTtSGULn0O6oS3KI dNsA== 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 a65si6121963pge.362.2021.10.21.00.09.41; Thu, 21 Oct 2021 00:09:56 -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 S231354AbhJUHKp (ORCPT + 99 others); Thu, 21 Oct 2021 03:10:45 -0400 Received: from smtprelay0103.hostedemail.com ([216.40.44.103]:54952 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231158AbhJUHKo (ORCPT ); Thu, 21 Oct 2021 03:10:44 -0400 Received: from omf04.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay07.hostedemail.com (Postfix) with ESMTP id 0533A180E07B8; Thu, 21 Oct 2021 07:08:28 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf04.hostedemail.com (Postfix) with ESMTPA id 95407D1514; Thu, 21 Oct 2021 07:08:24 +0000 (UTC) Message-ID: Subject: Re: [PATCH] virtio-blk: fixup coccinelle warnings From: Joe Perches To: cgel.zte@gmail.com, mst@redhat.com, Denis Efremov , Julia Lawall , Gilles Muller , Nicolas Palix , Michal Marek , cocci@inria.fr Cc: jasowang@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, axboe@kernel.dk, virtualization@lists.linux-foundation.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Ye Guojin , Zeal Robot Date: Thu, 21 Oct 2021 00:08:23 -0700 In-Reply-To: <20211021065111.1047824-1-ye.guojin@zte.com.cn> References: <20211021065111.1047824-1-ye.guojin@zte.com.cn> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.40.4-1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspamout03 X-Rspamd-Queue-Id: 95407D1514 X-Spam-Status: No, score=-0.04 X-Stat-Signature: w1k1cs1tg45sjhxa5ai68tet591rgwep X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX18GuLItoKjGI2brebfiEvCynGxVYaDHZyo= X-HE-Tag: 1634800104-276374 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2021-10-21 at 06:51 +0000, cgel.zte@gmail.com wrote: > From: Ye Guojin > > coccicheck complains about the use of snprintf() in sysfs show > functions: > WARNING use scnprintf or sprintf > > Use sysfs_emit instead of scnprintf or sprintf makes more sense. [] > diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c [] > @@ -624,7 +624,7 @@ cache_type_show(struct device *dev, struct device_attribute *attr, char *buf) > - return snprintf(buf, 40, "%s\n", virtblk_cache_types[writeback]); > + return sysfs_emit(buf, "%s\n", virtblk_cache_types[writeback]); Perhaps scripts/coccinelle/api/device_attr_show.cocci should be updated to be more like the script used in commit 1c7fd72687d6 @@ identifier d_show; identifier dev, attr, buf; @@ ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf) { <... return - sprintf(buf, + sysfs_emit(buf, ...); ...> } @@ identifier d_show; identifier dev, attr, buf; @@ ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf) { <... return - snprintf(buf, PAGE_SIZE, + sysfs_emit(buf, ...); ...> } @@ identifier d_show; identifier dev, attr, buf; @@ ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf) { <... return - scnprintf(buf, PAGE_SIZE, + sysfs_emit(buf, ...); ...> } @@ identifier d_show; identifier dev, attr, buf; expression chr; @@ ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf) { <... return - strcpy(buf, chr); + sysfs_emit(buf, chr); ...> } @@ identifier d_show; identifier dev, attr, buf; identifier len; @@ ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf) { <... len = - sprintf(buf, + sysfs_emit(buf, ...); ...> return len; } @@ identifier d_show; identifier dev, attr, buf; identifier len; @@ ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf) { <... len = - snprintf(buf, PAGE_SIZE, + sysfs_emit(buf, ...); ...> return len; } @@ identifier d_show; identifier dev, attr, buf; identifier len; @@ ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf) { <... len = - scnprintf(buf, PAGE_SIZE, + sysfs_emit(buf, ...); ...> return len; } @@ identifier d_show; identifier dev, attr, buf; identifier len; @@ ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf) { <... - len += scnprintf(buf + len, PAGE_SIZE - len, + len += sysfs_emit_at(buf, len, ...); ...> return len; } @@ identifier d_show; identifier dev, attr, buf; expression chr; @@ ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf) { ... - strcpy(buf, chr); - return strlen(buf); + return sysfs_emit(buf, chr); }