Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp291418pxm; Wed, 2 Mar 2022 15:35:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJyb3nTudZmiLhr4Y1T11zi4C/3Sbaz8ydshXd1eOkNlbJap08qDKn42ctNcw0+NkuASJxbX X-Received: by 2002:a17:902:f711:b0:14d:61ba:8baf with SMTP id h17-20020a170902f71100b0014d61ba8bafmr33220249plo.39.1646264158178; Wed, 02 Mar 2022 15:35:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646264158; cv=none; d=google.com; s=arc-20160816; b=L3Oj5Vb3ez+QjX3SNJEQIfD3WOiXwrPMIqSAdsaMaaNg70jau8ORiu3+qWsAKQwGLS DDr8Zh81CGALsFYj+usT4xVa1AX/gkOEnvSEifug64C67vsbcgffPaAuiSs8EjDZF23M b9ArfJh0eiU6j5JNHEeptUC+LyaYNHlZTGVh+ARbHbnjnrRrubEA9CO1uOD4nNn5/jNo S1v3QKi4fEFmmuhuyHUsquFrci+ZFx+lpOseW+aoPjXcMljdkt1+IySI1efccE71rbAI GBrSctOqqxE201VdyaF1J+KKLdqZYqiPvcLjH+c6gQe6HWTHCfPt5SrbLqtdPiiHHhTM Wa9Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=vplKU+u5BNo996K8f2xPSiatclDH2lB4T12dOrQIivE=; b=yl9graYfsjsVY0IE8h1P8f2DWQyAaWK8+H+Wt4/upheWLU7+OtzFWAT9sYFWxOqa81 e47bq912DaVp3QTxYEaZSz2+ssG1qnBzivZeRORuIBIgH0KIFxsiuSqiVbyxQG1osjFd MPU4HVDDIDa4u3nPSmdvYftBpe1+6+VDwH32JApqlC0hbMRYD7lPb5oBg1et0G4pQ8ii prcv1Z3fVdwYuC1RIdSvlM/OaL7dKV8GH9E52xDIkpOgalNL+Hr+NWe11V14N7t9CgZF xkDqr0nhqLHoabFtlg8WKlNwmS9SkgJoBxjVjU0eZMJVhlo1gk11Q0pYs1YQJ6bPSp8S sH8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="K/EOiYcs"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id e1-20020a656781000000b00378b905af35si444249pgr.417.2022.03.02.15.35.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 15:35:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="K/EOiYcs"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8C38B36E1E; Wed, 2 Mar 2022 15:03:58 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241749AbiCBMVg (ORCPT + 99 others); Wed, 2 Mar 2022 07:21:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241727AbiCBMVf (ORCPT ); Wed, 2 Mar 2022 07:21:35 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 968AA5BE7E for ; Wed, 2 Mar 2022 04:20:52 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id mg21-20020a17090b371500b001bef9e4657cso1276937pjb.0 for ; Wed, 02 Mar 2022 04:20:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vplKU+u5BNo996K8f2xPSiatclDH2lB4T12dOrQIivE=; b=K/EOiYcscZwk3AZTAYctKgHa6T/X/HoWmn9P6qtPVpTOHWomoZPugyFqWlNtT5kieI HQcEBb1VhOJMe0W0MgHN6Ivz2w6n0mg9WRL+EJ8h67RwbWxhEEuAvXeE9rXb+xSsAS2g 3xjTB5a5QowTYHuXZvULaTS/PyOq1IdzVVPIeamSowW0bB2daY+6Y6/CpJ4kfluPeTzL zRr7XYUdXQX5hgNqVZ8MFwxm5aULRW2tczjOtLmK3hHu0naFEi8ecYlBl0pVxrpt3+AE oJXqSaDDMOtzBsO9TEg1n7VlqCwjCNUNaQvFp/UOjBBmW5F6Lzbh6+s5oJtGVma42uUi YaSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vplKU+u5BNo996K8f2xPSiatclDH2lB4T12dOrQIivE=; b=FWzIf9F8pVfbjIZBPwabLi7fTF6jcypPvxPjD0G4qHCTg7P2B2BYcxtr+Fw5d464Bd 0clJtEIVKIJjDSFaj0u9VZvbHv4cbBOveSck14JaT0VJfXwJhVKwS97leWk6WQVCWBIr Shhh/tCavskRaIYY/ayRYGmEs/2C6ycNUI4yKJ6lVHexUMhVgtSH/ln+FReqiCgK5eRe zJDWRDC2yc3pX7iRIxM4qCdT0U/RngFiQOtnAykEWBtenKpxkKCMa9RuQD6KQESl634q BwmT9mG1awqAL1OHee/OXJpVqJxoJQcJZ/c76NU4v64JEMx0oxuWoqSPTFvNCU6rC5Lb Dxlg== X-Gm-Message-State: AOAM5316GTmg6GLYbWuTXLWH0ds+wUNfQg6OZI2TroKd7UFk0d+E3tdj YlZ/XHV2qEc9gOUjEALBrFGbKO+oG4Ns9w== X-Received: by 2002:a17:902:c111:b0:14f:c841:66e2 with SMTP id 17-20020a170902c11100b0014fc84166e2mr30558022pli.92.1646223651814; Wed, 02 Mar 2022 04:20:51 -0800 (PST) Received: from localhost.localdomain (bb42-60-144-185.singnet.com.sg. [42.60.144.185]) by smtp.gmail.com with ESMTPSA id na5-20020a17090b4c0500b001bc9301f316sm5046887pjb.42.2022.03.02.04.20.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 04:20:51 -0800 (PST) From: Nguyen Dinh Phi To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Nguyen Dinh Phi Subject: [PATCH RESEND] samples/kobject: Use sysfs_emit instead of snprintf Date: Wed, 2 Mar 2022 20:07:59 +0800 Message-Id: <20220302120759.380932-1-phind.uet@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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