From patchwork Sat Mar 20 07:14:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lars-Peter Clausen X-Patchwork-Id: 12152395 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 413B2C433E0 for ; Sat, 20 Mar 2021 11:25:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 10F936196F for ; Sat, 20 Mar 2021 11:25:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229849AbhCTLYs (ORCPT ); Sat, 20 Mar 2021 07:24:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229708AbhCTLYd (ORCPT ); Sat, 20 Mar 2021 07:24:33 -0400 Received: from www381.your-server.de (www381.your-server.de [IPv6:2a01:4f8:d0a:52ac::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3951AC0613AC for ; Sat, 20 Mar 2021 03:42:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=metafoo.de; s=default2002; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID; bh=7DISj2JMXOTkeZNyqhwtWoeYPCY7mWqhQZeSaoXXZ10=; b=H2fkM/SP2KRGsd0Oi/mOhfHGgx 0gsaDhA7JOiv4NzWtLE7GAJAcCcP4fZiBB+yiq4CuLx2JMbcIiaNjP+CNPwVX1DUBb/oHJn1XPSeM XpfIqZPkmVZHeXEEd/ClLlRJCQJtg0z3NSN4KHsOe9eer6Mkavaa2CNyxpZmCLVF+ui5U2WSmYvRc iCip0G6u+F58jUcZ95KkHHSmgRRbGVEEkVaBwF0sUaY+Y3KQLkMdshQSptOdxICAvJAVIJbC4BOEs EzG6Uh4RdWoh60YSmpypMU7T3RFNpBAz03AZwRLkxu5FxJEp0Mo4YHOINFUcXs1OWaBo4fbteEkhY 063V/+4A==; Received: from sslproxy02.your-server.de ([78.47.166.47]) by www381.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1lNVok-000AyM-1v; Sat, 20 Mar 2021 08:14:38 +0100 Received: from [2001:a61:2aa9:e001:9e5c:8eff:fe01:8578] (helo=lars-desktop.fritz.box) by sslproxy02.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lNVoj-000Vc8-TS; Sat, 20 Mar 2021 08:14:37 +0100 From: Lars-Peter Clausen To: Jonathan Cameron Cc: Joe Perches , linux-iio@vger.kernel.org, Lars-Peter Clausen Subject: [PATCH 2/4] iio: iio_enum_available_read(): Convert to sysfs_emit_at() Date: Sat, 20 Mar 2021 08:14:03 +0100 Message-Id: <20210320071405.9347-3-lars@metafoo.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210320071405.9347-1-lars@metafoo.de> References: <20210320071405.9347-1-lars@metafoo.de> MIME-Version: 1.0 X-Authenticated-Sender: lars@metafoo.de X-Virus-Scanned: Clear (ClamAV 0.102.4/26114/Sat Mar 20 04:43:32 2021) Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it knows about the sysfs buffer specifics and has some built-in sanity checks. Convert the iio_enum_available_read() function to use sysfs_emit_at() instead of scnprintf(). The conversion is straight forward, the only difference is that sysfs_emit_at() takes the buffers start address and an offset as parameters and already knows about the buffer's size limit. Signed-off-by: Lars-Peter Clausen --- drivers/iio/industrialio-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 058874af1242..e0fdf9141e09 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -504,7 +504,7 @@ ssize_t iio_enum_available_read(struct iio_dev *indio_dev, for (i = 0; i < e->num_items; ++i) { if (!e->items[i]) continue; - len += scnprintf(buf + len, PAGE_SIZE - len, "%s ", e->items[i]); + len += sysfs_emit_at(buf, len, "%s ", e->items[i]); } /* replace last space with a newline */