Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4420774rwb; Tue, 20 Sep 2022 13:44:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6xNVjHCIYNzPfGEgv//OL4R/EB6mgAOPnZHEzJDxSCpO8qNtGWdxV7937OlqRq9YGyG3q7 X-Received: by 2002:aa7:d98f:0:b0:454:44a0:f53e with SMTP id u15-20020aa7d98f000000b0045444a0f53emr7991525eds.425.1663706691666; Tue, 20 Sep 2022 13:44:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663706691; cv=none; d=google.com; s=arc-20160816; b=EKd+oACUs7g0O7ELJWb5V6IAeErugsA30uS+MXcXOjApEiM6TN/VCb3a17Ip9xddbI GTnN77ATeU6NiTrT00gaNaOZlOgY41O4DWrZXSFNczekp7sIloVmqk0h02n5hL7Kmzwv WY6cdFz3JPmqTuYGD81A4vsdlno+v/IEG/b9EgqhkTt4YVt9JL+rXdL1L2TXNMlyiNsU Hp+w8E/Q9hO7Y6rHbK2wTJ12Y5JZlp9V2GqOuHulJ5dXnkc+vfLMAfPTwqytH32sVvgb XOi8K1HCgz+ZHuXRrZsWgWJh1AzyN2OPXYImkwKBqGORpDJ0e9CJNyYLWeaHRzj0gHXr KXOQ== 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=B1QW5eCktyNKF1Kabrt/RgSIFVK+r7/SbP4DaTVv7K4=; b=ZtTOTPbXSRkp3fl7lorhrpbjCD4yNCPcfJ0vttG8mqcxQkvQwI0bzYx5WmWUp16kVK 7DzlVPPw3m/MI4ceMnUZzwRosApd3B6y7VsDgAQSmCNifIAenSdHkRSyh3xp33KC9apu Frxsw6aFFPShtBSGMsz3gJht3TyI2elafCpc5XiZ9Um8mdAAsW1gt2TotfI3PVusxCaY TszZWZzD6mJPUFsT7IqMgjqoLBC1Tc/NvJrN8brLExJsDNvQDh0bfWVfGjvA2nYxZZoc ZpIkY2H6aCmPgfBBhhxM1Aq5YtUoSvSRu8HT3UCI42phWciegfE2caOGtBnzaEkaO+0O yfnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CFtR9BmF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z10-20020a056402274a00b004549b880c67si914460edd.42.2022.09.20.13.44.25; Tue, 20 Sep 2022 13:44:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CFtR9BmF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231379AbiITUCB (ORCPT + 99 others); Tue, 20 Sep 2022 16:02:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231185AbiITUBw (ORCPT ); Tue, 20 Sep 2022 16:01:52 -0400 Received: from mail-oa1-x34.google.com (mail-oa1-x34.google.com [IPv6:2001:4860:4864:20::34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BB2952474 for ; Tue, 20 Sep 2022 13:01:45 -0700 (PDT) Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-1279948d93dso5874381fac.10 for ; Tue, 20 Sep 2022 13:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=B1QW5eCktyNKF1Kabrt/RgSIFVK+r7/SbP4DaTVv7K4=; b=CFtR9BmF/mRW3nRk8Fi0CTXIhc6ljBmuJPicWV16FOX/DcrG5bd5Xp7WKC34SqFRUF w1HC1d+7orsPsY5UIhG+6gq3wBT4/hCA1f7+5F8AEL4TZPakrdS2IYMIgaI/AYt6xVPK cMWNjErvdvZFch0+w4r9yGo1nnoJEx2grPtoxplFsoyajdlKE6Hf330LujxSsfv2VfEJ WQUUk/Nq89WsA2iIyf/PxjK+8EhXQ5Uep/Bd589gsdYG3UADxiIC3csqH1GzQSCrcix+ SoftkyB5dVVJoXZTX/PXsCCLz+20gNuhWp7bTExmcTZZeo3mCyQQdSGqGuH39+5wF/6a 4hmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=B1QW5eCktyNKF1Kabrt/RgSIFVK+r7/SbP4DaTVv7K4=; b=tBbNx1a3ph+3kWE5BpPEhGCr8vHLqJoHxu8waAnoRXDe2/PwX0gO14lTa2cbW2Bncq iL6u5BsGgE+lzMm8R9J2s79sCWsLsjfpCKnzWfZF3U1dgFEo08dJ9RZ6gPE/oYoNbgcI NVkr1QMp/foTbs7qnnQ7gNGATyx5CxXWnF7fRcq6oey1W7EhGOdNauPNYzskXrFTqBfw roDMxGJhLlXnqaGV4TQRozTzVwDpYznZ2Cfd2xcS6wO+E8Hs496MCboDPUFHnrwLC3gB eHm+FVdpnkEore+I1XOzkVlBApXllGRj+MdiBZP5vDq2IAxIAGzb2seT4BIlbVdob1QP PNLw== X-Gm-Message-State: ACrzQf115D4cUKgEuX4kz2pja11boY10vUWQDvdN4aMm7ex5fmMlbNJv ye4oYs9GUbi1RUpwXvKKu3gam80dgnBKOA== X-Received: by 2002:a05:6870:9a1a:b0:120:8d35:c740 with SMTP id fo26-20020a0568709a1a00b001208d35c740mr3183927oab.166.1663704104876; Tue, 20 Sep 2022 13:01:44 -0700 (PDT) Received: from fedora.attlocal.net (69-109-179-158.lightspeed.dybhfl.sbcglobal.net. [69.109.179.158]) by smtp.gmail.com with ESMTPSA id bm43-20020a0568081aab00b0034d14c6ce3dsm325634oib.16.2022.09.20.13.01.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 13:01:44 -0700 (PDT) From: William Breathitt Gray To: linux-iio@vger.kernel.org Cc: linux-kernel@vger.kernel.org, mranostay@ti.com, jpanis@baylibre.com, gwendal@chromium.org, bleung@chromium.org, groeck@chromium.org, jic23@kernel.org, david@lechnology.com, robertcnelson@gmail.com, William Breathitt Gray Subject: [PATCH v5 4/5] counter: Consolidate Counter extension sysfs attribute creation Date: Tue, 20 Sep 2022 13:21:28 -0400 Message-Id: <58e248e11fa839ef12ca883883c92bedddd8de77.1663693757.git.william.gray@linaro.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 Counter extensions are handled for the Device, Counts, and Signals. The code loops through each Counter extension and creates the expected sysfs attributes. This patch consolidates that code into functions to reduce redundancy and make the intention of the code clearer. Signed-off-by: William Breathitt Gray --- drivers/counter/counter-sysfs.c | 98 ++++++++++++++++----------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysfs.c index e5dd36e1a45f..b393da402e0b 100644 --- a/drivers/counter/counter-sysfs.c +++ b/drivers/counter/counter-sysfs.c @@ -592,6 +592,46 @@ static int counter_comp_id_attr_create(struct device *const dev, return 0; } +static int counter_ext_attrs_create(struct device *const dev, + struct counter_attribute_group *const group, + const struct counter_comp *const ext, + const enum counter_scope scope, + void *const parent, const size_t id) +{ + int err; + + /* Create main extension attribute */ + err = counter_attr_create(dev, group, ext, scope, parent); + if (err < 0) + return err; + + /* Create extension id attribute */ + return counter_comp_id_attr_create(dev, group, ext->name, id); +} + +static int counter_sysfs_exts_add(struct device *const dev, + struct counter_attribute_group *const group, + const struct counter_comp *const exts, + const size_t num_ext, + const enum counter_scope scope, + void *const parent) +{ + size_t i; + const struct counter_comp *ext; + int err; + + /* Create attributes for each extension */ + for (i = 0; i < num_ext; i++) { + ext = &exts[i]; + err = counter_ext_attrs_create(dev, group, ext, scope, parent, + i); + if (err < 0) + return err; + } + + return 0; +} + static struct counter_comp counter_signal_comp = { .type = COUNTER_COMP_SIGNAL_LEVEL, .name = "signal", @@ -605,8 +645,6 @@ static int counter_signal_attrs_create(struct counter_device *const counter, struct device *const dev = &counter->dev; int err; struct counter_comp comp; - size_t i; - struct counter_comp *ext; /* Create main Signal attribute */ comp = counter_signal_comp; @@ -620,21 +658,9 @@ static int counter_signal_attrs_create(struct counter_device *const counter, if (err < 0) return err; - /* Create an attribute for each extension */ - for (i = 0; i < signal->num_ext; i++) { - ext = &signal->ext[i]; - - err = counter_attr_create(dev, cattr_group, ext, scope, signal); - if (err < 0) - return err; - - err = counter_comp_id_attr_create(dev, cattr_group, ext->name, - i); - if (err < 0) - return err; - } - - return 0; + /* Add Signal extensions */ + return counter_sysfs_exts_add(dev, cattr_group, signal->ext, + signal->num_ext, scope, signal); } static int counter_sysfs_signals_add(struct counter_device *const counter, @@ -719,8 +745,6 @@ static int counter_count_attrs_create(struct counter_device *const counter, struct device *const dev = &counter->dev; int err; struct counter_comp comp; - size_t i; - struct counter_comp *ext; /* Create main Count attribute */ comp = counter_count_comp; @@ -743,21 +767,9 @@ static int counter_count_attrs_create(struct counter_device *const counter, if (err < 0) return err; - /* Create an attribute for each extension */ - for (i = 0; i < count->num_ext; i++) { - ext = &count->ext[i]; - - err = counter_attr_create(dev, cattr_group, ext, scope, count); - if (err < 0) - return err; - - err = counter_comp_id_attr_create(dev, cattr_group, ext->name, - i); - if (err < 0) - return err; - } - - return 0; + /* Add Count extensions */ + return counter_sysfs_exts_add(dev, cattr_group, count->ext, + count->num_ext, scope, count); } static int counter_sysfs_counts_add(struct counter_device *const counter, @@ -850,8 +862,6 @@ static int counter_sysfs_attr_add(struct counter_device *const counter, const enum counter_scope scope = COUNTER_SCOPE_DEVICE; struct device *const dev = &counter->dev; int err; - size_t i; - struct counter_comp *ext; /* Add Signals sysfs attributes */ err = counter_sysfs_signals_add(counter, cattr_group); @@ -888,19 +898,9 @@ static int counter_sysfs_attr_add(struct counter_device *const counter, if (err < 0) return err; - /* Create an attribute for each extension */ - for (i = 0; i < counter->num_ext; i++) { - ext = &counter->ext[i]; - - err = counter_attr_create(dev, cattr_group, ext, scope, NULL); - if (err < 0) - return err; - - err = counter_comp_id_attr_create(dev, cattr_group, ext->name, - i); - if (err < 0) - return err; - } + /* Add device extensions */ + return counter_sysfs_exts_add(dev, cattr_group, counter->ext, + counter->num_ext, scope, NULL); return 0; } -- 2.37.3