From patchwork Mon Aug 1 16:56:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 594730 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2ECAEC00144 for ; Mon, 1 Aug 2022 16:57:40 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id EE1E7844; Mon, 1 Aug 2022 18:56:48 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz EE1E7844 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1659373059; bh=wop0Z3RRD1c82qJpdEiyWFgl5ZoFiXjk6kMbqlhxgnk=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=mbbDS0ZRv1hnYnjsYOPKU3qw6cgmzA8ZVA9UXBuBRfZeQl2BsPXmOO/uJ/qEtav+6 Ip12Ug/C3J2i6ucxgyZD/+oqz6mMT14M9SUt5AXSs5u7BQLKY9+dq545CB14vMByoV wVUOk8KzIP/m5Qv94IQa1/2nfa++a9alxPjYQOzM= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 864ACF80152; Mon, 1 Aug 2022 18:56:48 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 09DFBF804FF; Mon, 1 Aug 2022 18:56:47 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 2AD97F80246 for ; Mon, 1 Aug 2022 18:56:42 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 2AD97F80246 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="PQP4IGU0"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="+a7BjUo/" Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D0FD820539; Mon, 1 Aug 2022 16:56:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1659373002; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/ovhgxr1ApFJXH9LbFiK1bb/hnw+jJ/+jjORILyeWn4=; b=PQP4IGU0kNuhN72RBjrzUNi3Ym5xvKUxSpZYkNH0JPs/kWqQDuMKZ1IH6Kcn5ZPou39tUn o1kSZhukInWS5ySsO3U2KVuKgKbeg718b4M6F8xFE4vetfGt1slbIx8nd7/qxDM9XlEpWg 8es8DPw6O8+LfWPn52Qww/eq6oD3iuc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1659373002; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/ovhgxr1ApFJXH9LbFiK1bb/hnw+jJ/+jjORILyeWn4=; b=+a7BjUo/TIv9bMu/1lDfjDH/0hHVSGsDczkACwfyAnpBSrApjs0Z5pTXLCGm8OjjJkXLIq LYZkA+JdX6QgnVBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id AF1E913ADF; Mon, 1 Aug 2022 16:56:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WP0CKsoF6GLXGgAAMHmgww (envelope-from ); Mon, 01 Aug 2022 16:56:42 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 1/7] ALSA: ac97: Replace sprintf() with sysfs_emit() Date: Mon, 1 Aug 2022 18:56:33 +0200 Message-Id: <20220801165639.26030-2-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220801165639.26030-1-tiwai@suse.de> References: <20220801165639.26030-1-tiwai@suse.de> MIME-Version: 1.0 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" For sysfs outputs, it's safer to use a new helper, sysfs_emit(), instead of the raw sprintf() & co. This patch replaces the open code straightforwardly with a new helper. Signed-off-by: Takashi Iwai --- sound/ac97/bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/ac97/bus.c b/sound/ac97/bus.c index 0d31a6d71468..045330883a96 100644 --- a/sound/ac97/bus.c +++ b/sound/ac97/bus.c @@ -460,7 +460,7 @@ static ssize_t vendor_id_show(struct device *dev, { struct ac97_codec_device *codec = to_ac97_device(dev); - return sprintf(buf, "%08x", codec->vendor_id); + return sysfs_emit(buf, "%08x", codec->vendor_id); } DEVICE_ATTR_RO(vendor_id); From patchwork Mon Aug 1 16:56:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 594729 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A6091C00144 for ; Mon, 1 Aug 2022 16:58:32 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id D111815F2; Mon, 1 Aug 2022 18:57:40 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz D111815F2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1659373110; bh=CML0OdqlNOy9XCOxCjrE1GWVUeg6kc8X79CXTGEv6jc=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=CZfIm+ErvJ5p/quLG8MCiwEhPDwHBY098mxlpYJr9/dCffwqnfQia/rzhZWVbmYB/ 6EKZK96nCTAzqA98LH3GxIhyVTzSmaOHQupAnOH7zcXl8t7LDcuNjU4r/hZNOl00QR fo/XjzO29nyRqfZueu8kFvMQ2LEqeFyKwJEiXIv8= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 3A108F80544; Mon, 1 Aug 2022 18:57:02 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 7E591F80551; Mon, 1 Aug 2022 18:56:51 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id EE534F8014B for ; Mon, 1 Aug 2022 18:56:43 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz EE534F8014B Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="mnXiXs4e"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="yt0t5kGo" Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id F314920633; Mon, 1 Aug 2022 16:56:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1659373002; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b/4/7H3+OptkylLM9OiNRuP/dwmGL/7B37zAuIZMM2A=; b=mnXiXs4eeEcU6cT4Yqq91zmidkzowMOhQaQlsQ3Q/nLFPuudAP/d0EhGEiL6353m1HlYW+ +d5RXmEtXGb2p+m9Vc6xzTlFPONSJCRyn4J0H1Dn6X7E/3PGLwnaZC9I6wudq0ZfiGrgpK 9vJuEDOXgUGyL7Ptz7wpAuaHnCxNvxc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1659373002; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b/4/7H3+OptkylLM9OiNRuP/dwmGL/7B37zAuIZMM2A=; b=yt0t5kGo1kdP9y3KuIYznG9ilgCqsIlvk+p3PlaN7t+/9BzvHMcdCyHPXscmZNA9es31Z1 PGdDD5eTSP9JYHDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D397113AAE; Mon, 1 Aug 2022 16:56:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8JXnMsoF6GLXGgAAMHmgww (envelope-from ); Mon, 01 Aug 2022 16:56:42 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 2/7] ALSA: aoa: Replace sprintf() with sysfs_emit() Date: Mon, 1 Aug 2022 18:56:34 +0200 Message-Id: <20220801165639.26030-3-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220801165639.26030-1-tiwai@suse.de> References: <20220801165639.26030-1-tiwai@suse.de> MIME-Version: 1.0 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" For sysfs outputs, it's safer to use a new helper, sysfs_emit(), instead of the raw sprintf() & co. This patch replaces such sprintf() calls with sysfs_emit() while simplifying the open code in modalias_show(); as modalias[] is a NUL-terminated string, we can pass it straightly to a printf() argument. Signed-off-by: Takashi Iwai --- sound/aoa/soundbus/sysfs.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/sound/aoa/soundbus/sysfs.c b/sound/aoa/soundbus/sysfs.c index dead3105689b..e87b28428b99 100644 --- a/sound/aoa/soundbus/sysfs.c +++ b/sound/aoa/soundbus/sysfs.c @@ -10,19 +10,13 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, { struct soundbus_dev *sdev = to_soundbus_device(dev); struct platform_device *of = &sdev->ofdev; - int length; - if (*sdev->modalias) { - strscpy(buf, sdev->modalias, sizeof(sdev->modalias) + 1); - strcat(buf, "\n"); - length = strlen(buf); - } else { - length = sprintf(buf, "of:N%pOFn%c%s\n", - of->dev.of_node, 'T', - of_node_get_device_type(of->dev.of_node)); - } - - return length; + if (*sdev->modalias) + return sysfs_emit(buf, "%s\n", sdev->modalias); + else + return sysfs_emit(buf, "of:N%pOFn%c%s\n", + of->dev.of_node, 'T', + of_node_get_device_type(of->dev.of_node)); } static DEVICE_ATTR_RO(modalias); @@ -32,7 +26,7 @@ static ssize_t name_show(struct device *dev, struct soundbus_dev *sdev = to_soundbus_device(dev); struct platform_device *of = &sdev->ofdev; - return sprintf(buf, "%pOFn\n", of->dev.of_node); + return sysfs_emit(buf, "%pOFn\n", of->dev.of_node); } static DEVICE_ATTR_RO(name); @@ -42,7 +36,7 @@ static ssize_t type_show(struct device *dev, struct soundbus_dev *sdev = to_soundbus_device(dev); struct platform_device *of = &sdev->ofdev; - return sprintf(buf, "%s\n", of_node_get_device_type(of->dev.of_node)); + return sysfs_emit(buf, "%s\n", of_node_get_device_type(of->dev.of_node)); } static DEVICE_ATTR_RO(type); From patchwork Mon Aug 1 16:56:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 594873 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 19878C00144 for ; Mon, 1 Aug 2022 16:59:38 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 59EC386E; Mon, 1 Aug 2022 18:58:46 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 59EC386E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1659373176; bh=a7ZYli3zwEc3NPRb6TCeo0s6OaDNsFq1z8j7Ftym5Ks=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=TrcbbQBTXU8FOno7TlnZlNZ6vGxSKQduj/F/WUwI7JiE2HwNVxH58C/96bGjWBj3/ Zy9PZtnORTTsa8zCc/dhBnQXWm+YwiUgiT0vv0GVqtoAeV2AQunTTSQ6tLsvugfAha FJfNgrFIyKXTuxQrmBg27aIBP7in30NWgyq87Ga4= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 94389F8057B; Mon, 1 Aug 2022 18:57:04 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id E717BF80543; Mon, 1 Aug 2022 18:56:55 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 25C23F80539 for ; Mon, 1 Aug 2022 18:56:43 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 25C23F80539 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="zwf/SAlX"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="mdaocXIJ" Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1C34B20634; Mon, 1 Aug 2022 16:56:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1659373003; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=en3FH7KP8atLaCOct0SjAHt2FjqcoX64pmm7Fiubz6Y=; b=zwf/SAlXrmA4XEFwta9xnAJx2cEzhKP9CgIImsleX1VGzP0QZqAfJI7gw3QE/AuWT3W7ol RUVFPaWLrvicZHmJJBqbZO/UnIvbpY1hlEc8Ry1YY/2v7jtuJPUM8Xsqx5iaOyoUSNhmnI If50MRykj5OvsCf+1bJg0ugtqrGewIM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1659373003; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=en3FH7KP8atLaCOct0SjAHt2FjqcoX64pmm7Fiubz6Y=; b=mdaocXIJYzvxIIQ/DWXt+cPYCdfYuQADUATVO+UGqQEYQfTyB2QtvIe3LBW07V64lK6vUJ GF8BpeoBcBiXnRAA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 010C713ADF; Mon, 1 Aug 2022 16:56:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SMobO8oF6GLXGgAAMHmgww (envelope-from ); Mon, 01 Aug 2022 16:56:42 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 3/7] ALSA: control-led: Replace sprintf() with sysfs_emit() Date: Mon, 1 Aug 2022 18:56:35 +0200 Message-Id: <20220801165639.26030-4-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220801165639.26030-1-tiwai@suse.de> References: <20220801165639.26030-1-tiwai@suse.de> MIME-Version: 1.0 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" For sysfs outputs, it's safer to use a new helper, sysfs_emit(), instead of the raw sprintf() & co. This patch replaces such sprintf() calls with sysfs_emit() while simplifying the open code in list_show(). Signed-off-by: Takashi Iwai --- sound/core/control_led.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/sound/core/control_led.c b/sound/core/control_led.c index 207828f30983..f975cc85772b 100644 --- a/sound/core/control_led.c +++ b/sound/core/control_led.c @@ -405,7 +405,7 @@ static ssize_t mode_show(struct device *dev, case MODE_ON: str = "on"; break; case MODE_OFF: str = "off"; break; } - return sprintf(buf, "%s\n", str); + return sysfs_emit(buf, "%s\n", str); } static ssize_t mode_store(struct device *dev, @@ -443,7 +443,7 @@ static ssize_t brightness_show(struct device *dev, { struct snd_ctl_led *led = container_of(dev, struct snd_ctl_led, dev); - return sprintf(buf, "%u\n", ledtrig_audio_get(led->trigger_type)); + return sysfs_emit(buf, "%u\n", ledtrig_audio_get(led->trigger_type)); } static DEVICE_ATTR_RW(mode); @@ -618,8 +618,7 @@ static ssize_t list_show(struct device *dev, struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev); struct snd_card *card; struct snd_ctl_led_ctl *lctl; - char *buf2 = buf; - size_t l; + size_t l = 0; card = snd_card_ref(led_card->number); if (!card) @@ -627,23 +626,19 @@ static ssize_t list_show(struct device *dev, down_read(&card->controls_rwsem); mutex_lock(&snd_ctl_led_mutex); if (snd_ctl_led_card_valid[led_card->number]) { - list_for_each_entry(lctl, &led_card->led->controls, list) - if (lctl->card == card) { - if (buf2 - buf > PAGE_SIZE - 16) - break; - if (buf2 != buf) - *buf2++ = ' '; - l = scnprintf(buf2, 15, "%u", - lctl->kctl->id.numid + - lctl->index_offset); - buf2[l] = '\0'; - buf2 += l + 1; - } + list_for_each_entry(lctl, &led_card->led->controls, list) { + if (lctl->card != card) + continue; + if (l) + l += sysfs_emit_at(buf, l, " "); + l += sysfs_emit_at(buf, l, "%u", + lctl->kctl->id.numid + lctl->index_offset); + } } mutex_unlock(&snd_ctl_led_mutex); up_read(&card->controls_rwsem); snd_card_unref(card); - return buf2 - buf; + return l; } static DEVICE_ATTR_WO(attach); From patchwork Mon Aug 1 16:56:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 594874 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C8C2AC00144 for ; Mon, 1 Aug 2022 16:59:11 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 1B4DC1616; Mon, 1 Aug 2022 18:58:20 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 1B4DC1616 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1659373150; bh=QcMc9dsuiImCG9KV6Oc9hFaGn0gaUlJvn84yoBLN2f0=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=qBy/WgwuXMDFklu1pkeRNIN1qO8YwHOYhZB+xAmAS62HL8iXPZj4O9Gff966+Ky80 zrEFmx6xnPr0/VXA1UJL0jzcIlxGNK+S733o1b4poUz0kJOy/Ba2c2PYat7K8r9F6S 4AQz3NgE38HyV6GkrBJw+tuaobuSRV2Hqrq/Y5SI= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 9FE9DF80567; Mon, 1 Aug 2022 18:57:03 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 47ACCF802DB; Mon, 1 Aug 2022 18:56:54 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 23993F80543 for ; Mon, 1 Aug 2022 18:56:43 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 23993F80543 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="kCowJgmf"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="RUrHO2zB" Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 406A44D844; Mon, 1 Aug 2022 16:56:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1659373003; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QmWWJhqS7XW5k3QO+2OS2cKY/x986gmeNg6L6vMhi0k=; b=kCowJgmfvPshf0APHc/eUn/UR5/+jxJYNm7xy1cCR+oJZ6ZzHB8/mjNYi4yEwgwN25Beab ea0mXzvbtgcd0hronRMuNsacwlhnPeJPxmUGCppS6SWhzxTYQ2en7oVWVRkRMUkrhBrDff BmcJzfYoAbbTO4S0ksIO1a+yuoq7XKM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1659373003; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QmWWJhqS7XW5k3QO+2OS2cKY/x986gmeNg6L6vMhi0k=; b=RUrHO2zBBuR/DjYqdXM2bVruMNOXdIw+zuxYyqmWFZ8aih8gKHxc/zm3mYVLgry3OV2C+y lcQ6/y4/NsxgJnAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2225913AAE; Mon, 1 Aug 2022 16:56:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id UB6zBssF6GLXGgAAMHmgww (envelope-from ); Mon, 01 Aug 2022 16:56:43 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 4/7] ALSA: core: Replace scnprintf() with sysfs_emit() Date: Mon, 1 Aug 2022 18:56:36 +0200 Message-Id: <20220801165639.26030-5-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220801165639.26030-1-tiwai@suse.de> References: <20220801165639.26030-1-tiwai@suse.de> MIME-Version: 1.0 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" sysfs_emit() is a new helper to simplify the sysfs string output. Replace the open-code with this new helper. Signed-off-by: Takashi Iwai --- sound/core/init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/core/init.c b/sound/core/init.c index 3ac95c66a4b5..193dae361fac 100644 --- a/sound/core/init.c +++ b/sound/core/init.c @@ -784,7 +784,7 @@ static ssize_t id_show(struct device *dev, struct device_attribute *attr, char *buf) { struct snd_card *card = container_of(dev, struct snd_card, card_dev); - return scnprintf(buf, PAGE_SIZE, "%s\n", card->id); + return sysfs_emit(buf, "%s\n", card->id); } static ssize_t id_store(struct device *dev, struct device_attribute *attr, @@ -822,7 +822,7 @@ static ssize_t number_show(struct device *dev, struct device_attribute *attr, char *buf) { struct snd_card *card = container_of(dev, struct snd_card, card_dev); - return scnprintf(buf, PAGE_SIZE, "%i\n", card->number); + return sysfs_emit(buf, "%i\n", card->number); } static DEVICE_ATTR_RO(number); From patchwork Mon Aug 1 16:56:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 594875 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B9623C00144 for ; Mon, 1 Aug 2022 16:58:38 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id EA7ED84B; Mon, 1 Aug 2022 18:57:46 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz EA7ED84B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1659373117; bh=Pj4jAb7sL0SqF6uyJQgVC/vuxgkcpTxLNPFNd7687wk=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=mDe9seW/zF1UUrg5tJn56EwuN24yBPA3Nx26ATMC6uhFrtXdxmWLuwTqrLbjCLcM7 61cwDpJAeUSUVcC/JU5Z9GsfHXjrukRLMGOPuMuROvugDOELKXQP/+oKl8p3vzkTmY im2Q87g/o0ugksxw1h+hLwoOj/q2Cnk8Dmb9K2A8= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id AD716F80558; Mon, 1 Aug 2022 18:57:02 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id BEDBCF80552; Mon, 1 Aug 2022 18:56:51 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id A1903F8023B for ; Mon, 1 Aug 2022 18:56:43 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz A1903F8023B Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="JBJOtxep"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="GdBUxXTC" Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7F25C4D854; Mon, 1 Aug 2022 16:56:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1659373003; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ww5jnaPCduGtXwHHgUSwExhF9QL4PYRD+iwmJrblojM=; b=JBJOtxepuX7NKXu7mJURUUq8hB+BuIC4+y2K9duvTa5LxlWsvpPZmo7DrtAU3ds7hHfAH8 MHpuFCdeEHGFv2V0NWOTaaCa884mgDPkoFSBqw+QdCYhVima5yCqaQo0edJGi9XJOa/Y5C NJ5hjG0jQQFkVrLuSZhtqkIF8P/lJh8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1659373003; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ww5jnaPCduGtXwHHgUSwExhF9QL4PYRD+iwmJrblojM=; b=GdBUxXTCPaTmE3xioirIy3yhxEeTHb9SU6PI2m4G1dL88tiGfEx0Yqs/lLurKVXAZAoxIn q0OsGqkkTgnGGHBg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 436AB13ADF; Mon, 1 Aug 2022 16:56:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qK+TD8sF6GLXGgAAMHmgww (envelope-from ); Mon, 01 Aug 2022 16:56:43 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 5/7] ALSA: pcm: Replace sprintf() with sysfs_emit() Date: Mon, 1 Aug 2022 18:56:37 +0200 Message-Id: <20220801165639.26030-6-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220801165639.26030-1-tiwai@suse.de> References: <20220801165639.26030-1-tiwai@suse.de> MIME-Version: 1.0 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" For sysfs outputs, it's safer to use a new helper, sysfs_emit(), instead of the raw sprintf() & co. This patch replaces such a sprintf() call straightforwardly with the new helper. Signed-off-by: Takashi Iwai --- sound/core/pcm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/core/pcm.c b/sound/core/pcm.c index 2ac742035310..82925709fa12 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -1031,7 +1031,7 @@ static ssize_t pcm_class_show(struct device *dev, str = "none"; else str = strs[pcm->dev_class]; - return sprintf(buf, "%s\n", str); + return sysfs_emit(buf, "%s\n", str); } static DEVICE_ATTR_RO(pcm_class); From patchwork Mon Aug 1 16:56:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 594727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 458D6C00144 for ; Mon, 1 Aug 2022 16:59:28 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id BC8E4E0E; Mon, 1 Aug 2022 18:58:36 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz BC8E4E0E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1659373166; bh=CRe5UFDdf5fOT4jlogk6falVoNa5rtyFYA3hlqbio0Y=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Lu4QFzp+s/e/lxy6uNLdipk80fLFUiaHwOBVUHJzSXu8BU6VnSRk6Pz5wG4sI0j2F fiPnwR0Rx0n63YNxOLPYnOy/pRI9XpTmDAMje6o7NJvY0r9ZtrRVWSZofMejaXuxSy HltsqwGvYc/WyMCfsKwWvfj3qo6LXSDh/7lZqzpg= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 20E4AF8056F; Mon, 1 Aug 2022 18:57:04 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id F0C35F8023B; Mon, 1 Aug 2022 18:56:55 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 24020F80544 for ; Mon, 1 Aug 2022 18:56:44 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 24020F80544 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="qN+3W+ZE"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="8u56CoYa" Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A70164D861; Mon, 1 Aug 2022 16:56:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1659373003; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eMOjodtbiTbrR19TsN4XkTkRKuEJ2fYirxstuXC06Cg=; b=qN+3W+ZELZ5mZKzXiIgbFNeHWDulchuMHtznGpEiF/hqAKTLEPbB+FqgDKiyHKRFy/gZQf 6yxxD1zuiTE45Kb7/gE1c5u11V+Y6tOQcVwdM6FodZP0wyA7hziZBJjfRGg2T1xKO3Og63 fIwYo4Cuf3LJE4nAQA/8vBj4hiQ3lc4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1659373003; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eMOjodtbiTbrR19TsN4XkTkRKuEJ2fYirxstuXC06Cg=; b=8u56CoYa5HhhDuQMszjVZPwgjvuOBQYcMkdtZCxVlbU66W4BYOVjIudfK4MmrnCZpu0ui7 sy3vKVOrjKJUKqCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8223D13AAE; Mon, 1 Aug 2022 16:56:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MJz7HssF6GLXGgAAMHmgww (envelope-from ); Mon, 01 Aug 2022 16:56:43 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 6/7] ALSA: hda: Replace sprintf() with sysfs_emit() Date: Mon, 1 Aug 2022 18:56:38 +0200 Message-Id: <20220801165639.26030-7-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220801165639.26030-1-tiwai@suse.de> References: <20220801165639.26030-1-tiwai@suse.de> MIME-Version: 1.0 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" For sysfs outputs, it's safer to use a new helper, sysfs_emit(), instead of the raw sprintf() & co. This patch replaces those usages straightforwardly with new helpers, sysfs_emit() and sysfs_emit_at(). Signed-off-by: Takashi Iwai --- sound/hda/hdac_sysfs.c | 42 +++++++++++++++++++-------------------- sound/pci/hda/hda_sysfs.c | 23 ++++++++++----------- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/sound/hda/hdac_sysfs.c b/sound/hda/hdac_sysfs.c index 0d7771fca9f0..e47de49a32e3 100644 --- a/sound/hda/hdac_sysfs.c +++ b/sound/hda/hdac_sysfs.c @@ -22,7 +22,7 @@ static ssize_t type##_show(struct device *dev, \ char *buf) \ { \ struct hdac_device *codec = dev_to_hdac_dev(dev); \ - return sprintf(buf, "0x%x\n", codec->type); \ + return sysfs_emit(buf, "0x%x\n", codec->type); \ } \ static DEVICE_ATTR_RO(type) @@ -32,8 +32,8 @@ static ssize_t type##_show(struct device *dev, \ char *buf) \ { \ struct hdac_device *codec = dev_to_hdac_dev(dev); \ - return sprintf(buf, "%s\n", \ - codec->type ? codec->type : ""); \ + return sysfs_emit(buf, "%s\n", \ + codec->type ? codec->type : ""); \ } \ static DEVICE_ATTR_RO(type) @@ -161,7 +161,7 @@ static struct kobj_type widget_ktype = { static ssize_t caps_show(struct hdac_device *codec, hda_nid_t nid, struct widget_attribute *attr, char *buf) { - return sprintf(buf, "0x%08x\n", get_wcaps(codec, nid)); + return sysfs_emit(buf, "0x%08x\n", get_wcaps(codec, nid)); } static ssize_t pin_caps_show(struct hdac_device *codec, hda_nid_t nid, @@ -169,8 +169,8 @@ static ssize_t pin_caps_show(struct hdac_device *codec, hda_nid_t nid, { if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) return 0; - return sprintf(buf, "0x%08x\n", - snd_hdac_read_parm(codec, nid, AC_PAR_PIN_CAP)); + return sysfs_emit(buf, "0x%08x\n", + snd_hdac_read_parm(codec, nid, AC_PAR_PIN_CAP)); } static ssize_t pin_cfg_show(struct hdac_device *codec, hda_nid_t nid, @@ -182,7 +182,7 @@ static ssize_t pin_cfg_show(struct hdac_device *codec, hda_nid_t nid, return 0; if (snd_hdac_read(codec, nid, AC_VERB_GET_CONFIG_DEFAULT, 0, &val)) return 0; - return sprintf(buf, "0x%08x\n", val); + return sysfs_emit(buf, "0x%08x\n", val); } static bool has_pcm_cap(struct hdac_device *codec, hda_nid_t nid) @@ -203,8 +203,8 @@ static ssize_t pcm_caps_show(struct hdac_device *codec, hda_nid_t nid, { if (!has_pcm_cap(codec, nid)) return 0; - return sprintf(buf, "0x%08x\n", - snd_hdac_read_parm(codec, nid, AC_PAR_PCM)); + return sysfs_emit(buf, "0x%08x\n", + snd_hdac_read_parm(codec, nid, AC_PAR_PCM)); } static ssize_t pcm_formats_show(struct hdac_device *codec, hda_nid_t nid, @@ -212,8 +212,8 @@ static ssize_t pcm_formats_show(struct hdac_device *codec, hda_nid_t nid, { if (!has_pcm_cap(codec, nid)) return 0; - return sprintf(buf, "0x%08x\n", - snd_hdac_read_parm(codec, nid, AC_PAR_STREAM)); + return sysfs_emit(buf, "0x%08x\n", + snd_hdac_read_parm(codec, nid, AC_PAR_STREAM)); } static ssize_t amp_in_caps_show(struct hdac_device *codec, hda_nid_t nid, @@ -221,8 +221,8 @@ static ssize_t amp_in_caps_show(struct hdac_device *codec, hda_nid_t nid, { if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) return 0; - return sprintf(buf, "0x%08x\n", - snd_hdac_read_parm(codec, nid, AC_PAR_AMP_IN_CAP)); + return sysfs_emit(buf, "0x%08x\n", + snd_hdac_read_parm(codec, nid, AC_PAR_AMP_IN_CAP)); } static ssize_t amp_out_caps_show(struct hdac_device *codec, hda_nid_t nid, @@ -230,8 +230,8 @@ static ssize_t amp_out_caps_show(struct hdac_device *codec, hda_nid_t nid, { if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) return 0; - return sprintf(buf, "0x%08x\n", - snd_hdac_read_parm(codec, nid, AC_PAR_AMP_OUT_CAP)); + return sysfs_emit(buf, "0x%08x\n", + snd_hdac_read_parm(codec, nid, AC_PAR_AMP_OUT_CAP)); } static ssize_t power_caps_show(struct hdac_device *codec, hda_nid_t nid, @@ -239,15 +239,15 @@ static ssize_t power_caps_show(struct hdac_device *codec, hda_nid_t nid, { if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_POWER)) return 0; - return sprintf(buf, "0x%08x\n", - snd_hdac_read_parm(codec, nid, AC_PAR_POWER_STATE)); + return sysfs_emit(buf, "0x%08x\n", + snd_hdac_read_parm(codec, nid, AC_PAR_POWER_STATE)); } static ssize_t gpio_caps_show(struct hdac_device *codec, hda_nid_t nid, struct widget_attribute *attr, char *buf) { - return sprintf(buf, "0x%08x\n", - snd_hdac_read_parm(codec, nid, AC_PAR_GPIO_CAP)); + return sysfs_emit(buf, "0x%08x\n", + snd_hdac_read_parm(codec, nid, AC_PAR_GPIO_CAP)); } static ssize_t connections_show(struct hdac_device *codec, hda_nid_t nid, @@ -261,8 +261,8 @@ static ssize_t connections_show(struct hdac_device *codec, hda_nid_t nid, if (nconns <= 0) return nconns; for (i = 0; i < nconns; i++) - ret += sprintf(buf + ret, "%s0x%02x", i ? " " : "", list[i]); - ret += sprintf(buf + ret, "\n"); + ret += sysfs_emit_at(buf, ret, "%s0x%02x", i ? " " : "", list[i]); + ret += sysfs_emit_at(buf, ret, "\n"); return ret; } diff --git a/sound/pci/hda/hda_sysfs.c b/sound/pci/hda/hda_sysfs.c index d5ffcba794e5..bf951c10ae61 100644 --- a/sound/pci/hda/hda_sysfs.c +++ b/sound/pci/hda/hda_sysfs.c @@ -33,7 +33,7 @@ static ssize_t power_on_acct_show(struct device *dev, { struct hda_codec *codec = dev_get_drvdata(dev); snd_hda_update_power_acct(codec); - return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_on_acct)); + return sysfs_emit(buf, "%u\n", jiffies_to_msecs(codec->power_on_acct)); } static ssize_t power_off_acct_show(struct device *dev, @@ -42,7 +42,7 @@ static ssize_t power_off_acct_show(struct device *dev, { struct hda_codec *codec = dev_get_drvdata(dev); snd_hda_update_power_acct(codec); - return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_off_acct)); + return sysfs_emit(buf, "%u\n", jiffies_to_msecs(codec->power_off_acct)); } static DEVICE_ATTR_RO(power_on_acct); @@ -55,7 +55,7 @@ static ssize_t type##_show(struct device *dev, \ char *buf) \ { \ struct hda_codec *codec = dev_get_drvdata(dev); \ - return sprintf(buf, "0x%x\n", codec->field); \ + return sysfs_emit(buf, "0x%x\n", codec->field); \ } #define CODEC_INFO_STR_SHOW(type, field) \ @@ -64,8 +64,8 @@ static ssize_t type##_show(struct device *dev, \ char *buf) \ { \ struct hda_codec *codec = dev_get_drvdata(dev); \ - return sprintf(buf, "%s\n", \ - codec->field ? codec->field : ""); \ + return sysfs_emit(buf, "%s\n", \ + codec->field ? codec->field : ""); \ } CODEC_INFO_SHOW(vendor_id, core.vendor_id); @@ -85,8 +85,8 @@ static ssize_t pin_configs_show(struct hda_codec *codec, int i, len = 0; mutex_lock(&codec->user_mutex); snd_array_for_each(list, i, pin) { - len += sprintf(buf + len, "0x%02x 0x%08x\n", - pin->nid, pin->cfg); + len += sysfs_emit_at(buf, len, "0x%02x 0x%08x\n", + pin->nid, pin->cfg); } mutex_unlock(&codec->user_mutex); return len; @@ -222,9 +222,8 @@ static ssize_t init_verbs_show(struct device *dev, int i, len = 0; mutex_lock(&codec->user_mutex); snd_array_for_each(&codec->init_verbs, i, v) { - len += scnprintf(buf + len, PAGE_SIZE - len, - "0x%02x 0x%03x 0x%04x\n", - v->nid, v->verb, v->param); + len += sysfs_emit_at(buf, len, "0x%02x 0x%03x 0x%04x\n", + v->nid, v->verb, v->param); } mutex_unlock(&codec->user_mutex); return len; @@ -272,8 +271,8 @@ static ssize_t hints_show(struct device *dev, int i, len = 0; mutex_lock(&codec->user_mutex); snd_array_for_each(&codec->hints, i, hint) { - len += scnprintf(buf + len, PAGE_SIZE - len, - "%s = %s\n", hint->key, hint->val); + len += sysfs_emit_at(buf, len, "%s = %s\n", + hint->key, hint->val); } mutex_unlock(&codec->user_mutex); return len; From patchwork Mon Aug 1 16:56:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 594728 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3EB7EC00144 for ; Mon, 1 Aug 2022 16:59:00 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 81E52886; Mon, 1 Aug 2022 18:58:08 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 81E52886 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1659373138; bh=qRve12a+z13PtRHdSIb5MeWO1AydoJzCJ5gB8ec8GZg=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=RW70CFirdIpQBbyNVe/YF2jgvNVfvaT4GQCDtwgDoLNQtgph7Zq1zvIia79mVmjLB pl8GsGvYwNuuCXBgbMjHifV+8r8veebRXWCKQTxMgwtnJwFUGY7DHzpBdRI6EuY/Qv v7q6x2h1rz+fz8MKShRQMwi6BUJPnFequun8KLy0= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 2A7E7F8055A; Mon, 1 Aug 2022 18:57:03 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 5B51FF8054A; Mon, 1 Aug 2022 18:56:52 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 1181FF802DB for ; Mon, 1 Aug 2022 18:56:44 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 1181FF802DB Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="SkHaj1gi"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="50HwP7n/" Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id EA78B2067B; Mon, 1 Aug 2022 16:56:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1659373003; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=toBsslfWCJJPflnUPbfZxL81dQGX6k4XqJBtdCj+KWk=; b=SkHaj1giv8XEdpdpioeVK2pYE9vrHoXbITJRgvdo1CuzRmAal8a10zITiTT3x99mqKWbfw TtJGG6EjYs8lK/EgdSBEk69oZeo46h/3hVn12iygHFjxs06RfDP7S5skV4L1O+hc2TS9Kl YllcN/MLaojc11lILyyx7paCPdoqnQc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1659373003; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=toBsslfWCJJPflnUPbfZxL81dQGX6k4XqJBtdCj+KWk=; b=50HwP7n/Zma5GbBZ+wdl9bQycZSlY565dtx7ioaFViQxOHkNYuKnKaZJI9HOE+dvJP+6Zw 0CtjZA3pCmgrjeCw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B1ACD13AAE; Mon, 1 Aug 2022 16:56:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ODYxKcsF6GLXGgAAMHmgww (envelope-from ); Mon, 01 Aug 2022 16:56:43 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 7/7] ALSA: line6: Replace sprintf() with sysfs_emit() Date: Mon, 1 Aug 2022 18:56:39 +0200 Message-Id: <20220801165639.26030-8-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220801165639.26030-1-tiwai@suse.de> References: <20220801165639.26030-1-tiwai@suse.de> MIME-Version: 1.0 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" For sysfs outputs, it's safer to use a new helper, sysfs_emit(), instead of the raw sprintf() & co. This patch replaces those usages straightforwardly with a new helper, sysfs_emit(). Signed-off-by: Takashi Iwai --- sound/usb/line6/pod.c | 8 ++++---- sound/usb/line6/podhd.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sound/usb/line6/pod.c b/sound/usb/line6/pod.c index 16e644330c4d..cd41aa7f0385 100644 --- a/sound/usb/line6/pod.c +++ b/sound/usb/line6/pod.c @@ -235,7 +235,7 @@ static ssize_t serial_number_show(struct device *dev, struct snd_card *card = dev_to_snd_card(dev); struct usb_line6_pod *pod = card->private_data; - return sprintf(buf, "%u\n", pod->serial_number); + return sysfs_emit(buf, "%u\n", pod->serial_number); } /* @@ -247,8 +247,8 @@ static ssize_t firmware_version_show(struct device *dev, struct snd_card *card = dev_to_snd_card(dev); struct usb_line6_pod *pod = card->private_data; - return sprintf(buf, "%d.%02d\n", pod->firmware_version / 100, - pod->firmware_version % 100); + return sysfs_emit(buf, "%d.%02d\n", pod->firmware_version / 100, + pod->firmware_version % 100); } /* @@ -260,7 +260,7 @@ static ssize_t device_id_show(struct device *dev, struct snd_card *card = dev_to_snd_card(dev); struct usb_line6_pod *pod = card->private_data; - return sprintf(buf, "%d\n", pod->device_id); + return sysfs_emit(buf, "%d\n", pod->device_id); } /* diff --git a/sound/usb/line6/podhd.c b/sound/usb/line6/podhd.c index b24bc82f89e3..ffd8c157a281 100644 --- a/sound/usb/line6/podhd.c +++ b/sound/usb/line6/podhd.c @@ -146,7 +146,7 @@ static ssize_t serial_number_show(struct device *dev, struct snd_card *card = dev_to_snd_card(dev); struct usb_line6_podhd *pod = card->private_data; - return sprintf(buf, "%u\n", pod->serial_number); + return sysfs_emit(buf, "%u\n", pod->serial_number); } static ssize_t firmware_version_show(struct device *dev, @@ -155,7 +155,7 @@ static ssize_t firmware_version_show(struct device *dev, struct snd_card *card = dev_to_snd_card(dev); struct usb_line6_podhd *pod = card->private_data; - return sprintf(buf, "%06x\n", pod->firmware_version); + return sysfs_emit(buf, "%06x\n", pod->firmware_version); } static DEVICE_ATTR_RO(firmware_version);