Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3100773pxj; Sun, 20 Jun 2021 10:02:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoRyzhP1792DyogQ9CK2sxDmd3O5AjhIwHBlU1z3RBfnsnmQAQoVcOJJjQVQssTmRvkTAq X-Received: by 2002:a05:6602:2bfc:: with SMTP id d28mr12195254ioy.39.1624208558310; Sun, 20 Jun 2021 10:02:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624208558; cv=none; d=google.com; s=arc-20160816; b=D1erXXsJPRBhYxKMsLjZ1ysi+JF4TX3xMxDF7dBlGYhYDr3YIPznjqplkAI/CBsAGw OkpiLrfROf3HbBQfvIO3LNZiV9d/qXC7M5ar6S900wmVy9RG61VZVBl8zZmjFtA+E7ph aQhKOXvIebP77meWy9Iq4E4b882WGzbJHiCroCWSvcwlMWT6KoxSGzIK0wch9//Ed6Lq HeV4o/dEXB2ETslVqlndMh0d8/1TgxDs6kUZj9m+8xeaFx358PFfY3GIUIqqZc1+ZH1W BoxhiC6Ek6EHdQMiyVnjJJOBh4vkrW59D8xbhBq5WRIyx910IqjA02hJiOC1VodvhDdV GF2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=vplKU+u5BNo996K8f2xPSiatclDH2lB4T12dOrQIivE=; b=DXe9UKh3VUF3AiSiwrRetL/f21dOKpyniriZhgsDxxvpqlAc253enq/JG/nlVgckn/ OlCW3UQRmctLv6f3quNj3iYEV97nisA7LyiIple2g6bHcGS8lAXxw7FISpPlXdJcsLqc nY8tIQYlncdyAzao980QxHjLtV80VTf6VFqV3046Jx44NNcDe93lmMApwAi8cSrtdfg3 lGbZPONr7nwFXOfxCvVMnfCt9vIBb4O2XtWOZnU10/hQRfpVAux3+xm2Fl+lgK+BUNej Q+K4r/a5UEhLTkfjxUxTMXOeGR2B0onqZIxjCOPpOCepy8iFrqEzsjd2yO3SiWLYVtRK ZqqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=QWRnGHvK; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g13si9033226ild.161.2021.06.20.10.02.16; Sun, 20 Jun 2021 10:02:38 -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=fail header.i=@gmail.com header.s=20161025 header.b=QWRnGHvK; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229943AbhFTRCY (ORCPT + 99 others); Sun, 20 Jun 2021 13:02:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229605AbhFTRCT (ORCPT ); Sun, 20 Jun 2021 13:02:19 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35C4BC061574 for ; Sun, 20 Jun 2021 10:00:06 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id x19so7270575pln.2 for ; Sun, 20 Jun 2021 10:00:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vplKU+u5BNo996K8f2xPSiatclDH2lB4T12dOrQIivE=; b=QWRnGHvKw4OmAKVdb7g4PrPt4DMjFNMI71DYvWPQ4o/2KNDm5Qkf3YSvllvOT4zbdy M6ouf/4FnHr4JaLLnP/nLaZwQm5mJOx7JxUQ8PSRpniVhAiUDdFbex4xd43tOdGIx/BZ Dsi6pfRoLE007Y3fTwSvXaGMcyRUHs9yloP5tnDID46zrspB6QHtkHxnz//fo5xMlvhY uc10QAajHXZ+wH6X6J620X8DFV6WPwujfAcl7vJ1eQMU9epbqLmxXDqrrilmsUYZZ9jV F0dGkmOu3NgPbm8AFQ2XiEww5Mkmg+X3DxLZnaBM7CsqIfP7L0VJvwJ7iW6Ez9YiTQb2 oqLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vplKU+u5BNo996K8f2xPSiatclDH2lB4T12dOrQIivE=; b=hcF5YuIMcQvUob6l8j4nLw8rHEwD3+wdxj9Ez78TLRDyizO1usasLzqNPxH1n6seS4 McyjtSnw4WVfg+QIBmRgnP/1o9KG+PmK3oXRUpDu//MCxq33Y+4xG4fkxIO0jMlzf/Mm T/rA4Jz2PIz8k19qefOfcs79b9LCRlTsumukVKBSbWWcUbRl3AG+Ys9ktv2P6Yoy0iIF /Pn1TsqP/kOCNVhg6pqeGM08rPNj9Qr9GL76NMSFt292UaXk14lGO8yV/PV5S4rs603X z30XXxzDIIpnTVw4O3NQOGtWItjl5qui+5CclOJV2VKN/R6CF2fuR446NpFvMaFrwOrE zLxg== X-Gm-Message-State: AOAM5316C8xbY30+ja7vQZdhdP2I+oqRIC/cM014vGtRA8p71MHkzyU6 UWnqXLyoXNeNf9x2ZUIT7RNuOvLKCAeIhOHc X-Received: by 2002:a17:90a:8804:: with SMTP id s4mr22648275pjn.200.1624208405401; Sun, 20 Jun 2021 10:00:05 -0700 (PDT) Received: from pn-hyperv.lan (bb42-60-144-185.singnet.com.sg. [42.60.144.185]) by smtp.gmail.com with ESMTPSA id i128sm13554263pfc.142.2021.06.20.10.00.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Jun 2021 10:00:05 -0700 (PDT) From: Nguyen Dinh Phi Cc: linux-kernel@vger.kernel.org Subject: [PATCH] samples/kobject: Use sysfs_emit instead of snprintf Date: Mon, 21 Jun 2021 01:00:01 +0800 Message-Id: <20210620170001.224583-1-phind.uet@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Convert sprintf() to sysfs_emit() in order to check buffer overrun on sysfs outputs. Signed-off-by: Nguyen Dinh Phi --- samples/kobject/kobject-example.c | 4 ++-- samples/kobject/kset-example.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/kobject/kobject-example.c b/samples/kobject/kobject-example.c index 9e383fdbaa00..96678ed73216 100644 --- a/samples/kobject/kobject-example.c +++ b/samples/kobject/kobject-example.c @@ -28,7 +28,7 @@ static int bar; static ssize_t foo_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - return sprintf(buf, "%d\n", foo); + return sysfs_emit(buf, "%d\n", foo); } static ssize_t foo_store(struct kobject *kobj, struct kobj_attribute *attr, @@ -60,7 +60,7 @@ static ssize_t b_show(struct kobject *kobj, struct kobj_attribute *attr, var = baz; else var = bar; - return sprintf(buf, "%d\n", var); + return sysfs_emit(buf, "%d\n", var); } static ssize_t b_store(struct kobject *kobj, struct kobj_attribute *attr, diff --git a/samples/kobject/kset-example.c b/samples/kobject/kset-example.c index c8010f126808..52f1acabd479 100644 --- a/samples/kobject/kset-example.c +++ b/samples/kobject/kset-example.c @@ -112,7 +112,7 @@ static void foo_release(struct kobject *kobj) static ssize_t foo_show(struct foo_obj *foo_obj, struct foo_attribute *attr, char *buf) { - return sprintf(buf, "%d\n", foo_obj->foo); + return sysfs_emit(buf, "%d\n", foo_obj->foo); } static ssize_t foo_store(struct foo_obj *foo_obj, struct foo_attribute *attr, @@ -144,7 +144,7 @@ static ssize_t b_show(struct foo_obj *foo_obj, struct foo_attribute *attr, var = foo_obj->baz; else var = foo_obj->bar; - return sprintf(buf, "%d\n", var); + return sysfs_emit(buf, "%d\n", var); } static ssize_t b_store(struct foo_obj *foo_obj, struct foo_attribute *attr, -- 2.25.1