From patchwork Sat Sep 17 00:39:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 12978945 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2118C6FA8B for ; Sat, 17 Sep 2022 01:16:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229806AbiIQBQh (ORCPT ); Fri, 16 Sep 2022 21:16:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229774AbiIQBQf (ORCPT ); Fri, 16 Sep 2022 21:16:35 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75A80BBA76 for ; Fri, 16 Sep 2022 18:16:34 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id o7so13326514qkj.10 for ; Fri, 16 Sep 2022 18:16:34 -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=u9zxwUyjTnHb6dXIFQytfA/XLHMka2VsioSd5KiJT2E=; b=T/Y8ua4PR5ZmLcpi7HRFvkzn7jZk7obT+HVwyyLypu3Z1ZIl0KNujdoZx+z4OmAzz6 TJQFWdYzFKGCwqKENxHWssZ1PnUs9QDoJ1iorroNn+UAhlCSo7axHpiOVleErxClxdkj zqHmSMxa56vFP9BUqzJUtoKsST46cprAjcKIHdnK5B6SotbRg4CKJ6t/0AZ4J7a5wxix /C5x7InFB3xbzkY6lhu6IYaExG1dN+d5rSNFufSKyUV1DCOflRlSDCrxLXl37pCDodrb PGrYxUXfuoRxQLBl4Zuesq1t4Cq7ZTwU5qTFqX5CLKfax7CUOSlf8DXau8+/ahZGruer Vl2g== 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=u9zxwUyjTnHb6dXIFQytfA/XLHMka2VsioSd5KiJT2E=; b=KFPK99yc3z/n7W9mOpYTnxm5BGd2rzwvxC0Ef88DZ/DH4p8YziFM2NQuQPi3HL51yu apBI61YZ//1Y6J3xu5z99G2+w9dP8BjbscQpPc8dpzw+rlwUE6bO7SEo0rsIsjYdcvIH GiJGSrIUtndDDLcWv56rpueJbizNhl4lUlB3kyzd4Hvcde6ZdZ/Sz67B7xm7bOGiQwhQ CaRhg764W/FR6fdrxr1i2CUjALNUE2tutn2PpX0WehsXZX30dMBJJVbVYSqEUk2Iuktd 5+KT7BBqVovUkfwwLLcXbxNWDzzdE1iHrkmKctl9Um0kgilOhAsUCT3gSrl4mNFZPf8e y8Mg== X-Gm-Message-State: ACrzQf08fEzsGtPseX/tL5r9GCJTO3h9OG+ULaL7yWUOkIcYlooOAZE1 /5YAz5SkufykYaj5U6s+FEl889fVuNTNtg== X-Google-Smtp-Source: AMsMyM4PhBnQfuUl3GK8Arbg7pQCPy4qG/RQWLpyzNL8rLOEreCkIHmk/WL5P3jjk9yQ2N+MyPcGgQ== X-Received: by 2002:a37:38d:0:b0:6cd:fd39:10e5 with SMTP id 135-20020a37038d000000b006cdfd3910e5mr5973510qkd.784.1663377393535; Fri, 16 Sep 2022 18:16:33 -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 v6-20020a05620a440600b006bb87c4833asm8085434qkp.109.2022.09.16.18.16.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 18:16:33 -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 v2 3/4] counter: Consolidate Counter extension sysfs attribute creation Date: Fri, 16 Sep 2022 20:39:27 -0400 Message-Id: <9fa4b496be11ea25aaef2c0515ec80a50827a498.1663372750.git.william.gray@linaro.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@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 92d3d4f549cb..7ce7c51395da 100644 --- a/drivers/counter/counter-sysfs.c +++ b/drivers/counter/counter-sysfs.c @@ -591,6 +591,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", @@ -604,8 +644,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; @@ -619,21 +657,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, @@ -718,8 +744,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; @@ -742,21 +766,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, @@ -849,8 +861,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); @@ -887,19 +897,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; }