From patchwork Thu Nov 30 10:54:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 171829 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp296204vqy; Thu, 30 Nov 2023 02:56:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGL2sZlELR4ysIvu2+/fGSsNEg+RjvlpVrGlP2SxX1RBvUp/lBAJUNkIE3XBIGFjiunD/T X-Received: by 2002:a05:6e02:1945:b0:35c:81ed:878f with SMTP id x5-20020a056e02194500b0035c81ed878fmr19604407ilu.11.1701341786516; Thu, 30 Nov 2023 02:56:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701341786; cv=none; d=google.com; s=arc-20160816; b=eFIobJ8GJtIi4jBYzRoceURyZngkfVnIVi/Q8JvnVRnkbT+SeJ/1A0v2l953rnw2RH cLe7tUtSg+cPi1hkbjOgPgov9CXszO7A62T+DDg9BYkj/LHz4BOodMGu/SIAn7DWyEVw igpov3CyJWY0vUY4w4Q8O+bfpm7I/nDsHyd/meIDFBRK20DLyTY5qFYa7OrM+VDtIjUz 2EwwFGU5I0V/ck3IVtlXnrq3m6mvqsICjIAa3MAOwQVPK9HAshCwlj1ECxi4aJz21aST LrXOZ9KOSXm49nfwXyM7khchh+M6vHQ5JjLeTbcacxfiVJn5z+LHoZrV0uYIQy4zvwHu fSDw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=siZEx6QlTlU7yBJ95DA4dKRSNb5nQW98f3glB77bt4o=; fh=6lIH5Orw3Z32jZlgFsLTy/ys6XO2U2mTE3pq86XGXJ8=; b=ld0JG8zlzjBU8oxCCgUOIiwitURbQ68vNr/KBF744fNvaa4Qavv8R9J2PBSU+I95qe 8yo9BA3Tazfu5ezi9vUwLov9da1AjZ58YT2g/hnDxwg0gosiubr4i/M+VT26Kh4rWPSm mM8MoHgspvG0c4dQ8Ve2g9U05Zfk+/QEuAnfhlI/cmDiMNMG0wVCAa42xVHJhAxNs2fR 4sGHqAuthuVhrNGfA3i7mvMTBMlYvpSn82YsGkLO0s42To+KJ1D3aqhUZjGX7rkSXjot 0atIK4KBRH4BYInHa87IZt95jKFn7EotMfN52YdwgkzUk9yv8zorAwRzaMs6tyZW0dbj HTFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="M/7ElH+x"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id l68-20020a632547000000b005be1ee5dd00si1002846pgl.764.2023.11.30.02.56.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 02:56:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="M/7ElH+x"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 1410F807D9B6; Thu, 30 Nov 2023 02:55:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345135AbjK3KzR (ORCPT + 99 others); Thu, 30 Nov 2023 05:55:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345081AbjK3KzM (ORCPT ); Thu, 30 Nov 2023 05:55:12 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 100AB10FA for ; Thu, 30 Nov 2023 02:55:19 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A841AC433CA; Thu, 30 Nov 2023 10:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701341718; bh=/XOh9djbd1kRjRIJaFEo79gsQogKZILFqya3ZNX3dzE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M/7ElH+xTwmRE/jQTEQPLVFtUUURsQO7RbtCR9vxOg5H7Gx4ArBGSB9MkUmH5CF5E szynq61yJlRo4ltLpVSCDAMrZQiXgH3j9/qyA5woBqJqjsVy/uNlp5VKKajiNyCKMZ PmuSoGJGgyI611UCzIabzZySOnX+87zpCgULh+zKjXnF2nIZ/BvI58pKkaOUWM8ick mvUGbVqUhRs7VMauF6ygzEG+4Evd0+RI9YYZKy8aEaVn6ng2JizzUyalZjjxkT5LYG ylBtp51MF9qOLB6skfhw2WPf5GU7v6YFGgPJTTiemGSiESLpG1GExPLuPpuFzsZXvR FQ7MWMmPFKteQ== From: Lee Jones To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , linux-usb@vger.kernel.org Subject: [PATCH 4/5] usb: gadget: Remove snprintf() from sysfs call-backs and replace with sysfs_emit() Date: Thu, 30 Nov 2023 10:54:38 +0000 Message-ID: <20231130105459.3208986-5-lee@kernel.org> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog In-Reply-To: <20231130105459.3208986-1-lee@kernel.org> References: <20231130105459.3208986-1-lee@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 30 Nov 2023 02:55:43 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783986165189440192 X-GMAIL-MSGID: 1783986165189440192 Since snprintf() has the documented, but still rather strange trait of returning the length of the data that *would have been* written to the array if space were available, rather than the arguably more useful length of data *actually* written, it is usually considered wise to use something else instead in order to avoid confusion. In the case of sysfs call-backs, new wrappers exist that do just that. This patch replaces just one use of snprintf() found in the sysfs .show() call-back with the new sysfs_emit() helper. Link: https://lwn.net/Articles/69419/ Link: https://github.com/KSPP/linux/issues/105 Cc: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org Signed-off-by: Lee Jones --- drivers/usb/gadget/configfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index 4c639e9ddedc0..b7d2a1313a684 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -812,7 +812,7 @@ static ssize_t gadget_string_s_show(struct config_item *item, char *page) struct gadget_string *string = to_gadget_string(item); int ret; - ret = snprintf(page, sizeof(string->string), "%s\n", string->string); + ret = sysfs_emit(page, "%s\n", string->string); return ret; }