From patchwork Wed Apr 19 21:07:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 85550 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp669640vqo; Wed, 19 Apr 2023 14:16:09 -0700 (PDT) X-Google-Smtp-Source: AKy350YHzBTS55KMYTUzVYXZpsTiUbM+1rku4u5ju7Ugowp5+75KJsgn7+eov3KyYIMGN1BDJHCh X-Received: by 2002:a05:6a00:2289:b0:63b:5174:4784 with SMTP id f9-20020a056a00228900b0063b51744784mr6009358pfe.30.1681938969442; Wed, 19 Apr 2023 14:16:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681938969; cv=none; d=google.com; s=arc-20160816; b=IK6Y9H9Egfa/lUo5quFcDE0E01ExBT2DruRxymPK1lpvG47PNp4CjLTSMkBzbSpX0i YUhtg0duqGzJRksWK26diO8r82VdbHnObKlmMBmjvuYRzf5di58Mq6GO4m2u7oj4xuTV zZ0KysojJaQ6ktTD5Ys3PsYIRMseBWwUi3QDCcQ9Be8fDkhO5wwYwtEKv0EoHL5bwtdi Xx4k4uoS6GicuQBnHP/WWxfkL68UA4TxkdTq230pb/0tWMEMcQEYUN7kh1JCH9CmGMAs LfAq1oUeEUalAXJeYU42I1vVoxyFINJ0h6wvr/12+FUfpl5JiY+9TjfWLbtJJNzp65FH 5Drg== 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:to:from :dkim-signature; bh=rnAvpgJtv8CT4PCBV0v1f+gT06nFs4wcweY9SHoaOe4=; b=OL6hfD4WskbFcoiTIbjt5nWa9VaFD+L9Oa4AYMyXyhP5zIdA9wgC4WZ15zTEM+Gx/q e67NRKtSZzS88YGE8R7afKBzF4kSHxoK+hbycQp8iQkZL66E4A6B+DbB0cfewD2S2wCZ qGh22mtWlLQHAjjDUdMeFmZ35cBh2NgjWSod3I4VUJ9bfsY1oyvFEInDwcIg1FzjHxUW pWQci1gaAVCvpUx3ZI9JB8h78zOS+I2JlQely2gVgvOr9rT2Oghn8KtqzLVbLcZlNkt5 T9Yih2yS38LCq74pOiRSWSO4Qn5zRnIPTCCYYNPNfevUAfe+EDGvUBC1tzLyE3zAyS40 ARcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Gxa5hgO2; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j67-20020a625546000000b0063473a51539si16403561pfb.398.2023.04.19.14.15.53; Wed, 19 Apr 2023 14:16:09 -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=@gmail.com header.s=20221208 header.b=Gxa5hgO2; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231500AbjDSVIe (ORCPT + 99 others); Wed, 19 Apr 2023 17:08:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231497AbjDSVI2 (ORCPT ); Wed, 19 Apr 2023 17:08:28 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65C1F5BB2; Wed, 19 Apr 2023 14:08:20 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3f0a80b686eso1202865e9.1; Wed, 19 Apr 2023 14:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681938499; x=1684530499; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=rnAvpgJtv8CT4PCBV0v1f+gT06nFs4wcweY9SHoaOe4=; b=Gxa5hgO2fbz+1mGgBavdX42YSG9adBCLJcXMD7lqySdsOWAigehdu2GrvA89FsztyZ fWHnK7y5Qmf1xDw5VH+PXzYWRg1SFbg83ffni13yXtOz07yM2vaCopXbgeJysOVgIuOR Sgx/hDM7Oy0ndZzQTOXUrDyrnjMlOZZKhBgu2od8189h9TZa5tTVGtydgmH+D1BZIb9A KQ9SmTaqjIT/l8UXf85hunnBzjGFUY6ZBn30r/URt/Gsr1fcwVRb2tzeOCNL+3OKEOKb ID+sYhUEDa1ZUMPQMGIKwvmsSB58+Ql/Jbd25cy6EXoEcW6FIzMVByArrRRvBv1IP25/ H4oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681938499; x=1684530499; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rnAvpgJtv8CT4PCBV0v1f+gT06nFs4wcweY9SHoaOe4=; b=l/tNdxdcahjvwm78x1j+GilU3/iw/R8KqvkCDbZzATviu2WAl8AsGrAg8HYm5q2A0Q Z9YXQLAT9YnRiIZzsXdXFOqFm3/V241pYyjhrJU4a63zr3bIt8j4cXfgsz1sb4QddqrH LnWRhoe/uD181s9C4+ArIPCWath+jMUxaDPH2Xv9LpCkz8V0EkUgYH0sCxDOIQU/eS5/ h1XsFGsfzlYlC+CetA16LjWThDu5QaT4nv0JKPu5PDMPp2tBnF6QLr32ve6QPvXT2i23 9zRhf0gFK5LJBOUNbccCQ5tZk6onIAI/CvQp2vrYEUNgF80cwI9/PykoWQlFu3sJbcBs iDWg== X-Gm-Message-State: AAQBX9cG12kyzsy8XKSdM6LRBXua/kJGLlFlqbMXHJI+fq3931C7hY+o 40UQwuEhMQ2i8lkOh0lx+q8= X-Received: by 2002:adf:e791:0:b0:2fc:7a4:839b with SMTP id n17-20020adfe791000000b002fc07a4839bmr5380969wrm.61.1681938498828; Wed, 19 Apr 2023 14:08:18 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id g3-20020a5d5543000000b002fe254f6c33sm81295wrw.92.2023.04.19.14.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 14:08:18 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Christian Marangi , Martin Schiller , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Lunn Subject: [PATCH 4/5] leds: trigger: netdev: convert device attr to macro Date: Wed, 19 Apr 2023 23:07:42 +0200 Message-Id: <20230419210743.3594-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230419210743.3594-1-ansuelsmth@gmail.com> References: <20230419210743.3594-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763640836686226859?= X-GMAIL-MSGID: =?utf-8?q?1763640836686226859?= Convert link tx and rx device attr to a common macro to reduce common code and in preparation for additional attr. Signed-off-by: Christian Marangi Reviewed-by: Andrew Lunn --- drivers/leds/trigger/ledtrig-netdev.c | 57 ++++++++------------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 0d4649e7a84d..5a47913c813c 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -198,47 +198,22 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, return size; } -static ssize_t link_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return netdev_led_attr_show(dev, buf, NETDEV_ATTR_LINK); -} - -static ssize_t link_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t size) -{ - return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_LINK); -} - -static DEVICE_ATTR_RW(link); - -static ssize_t tx_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return netdev_led_attr_show(dev, buf, NETDEV_ATTR_TX); -} - -static ssize_t tx_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t size) -{ - return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_TX); -} - -static DEVICE_ATTR_RW(tx); - -static ssize_t rx_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return netdev_led_attr_show(dev, buf, NETDEV_ATTR_RX); -} - -static ssize_t rx_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t size) -{ - return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_RX); -} - -static DEVICE_ATTR_RW(rx); +#define DEFINE_NETDEV_TRIGGER(trigger_name, trigger) \ + static ssize_t trigger_name##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ + { \ + return netdev_led_attr_show(dev, buf, trigger); \ + } \ + static ssize_t trigger_name##_store(struct device *dev, \ + struct device_attribute *attr, const char *buf, size_t size) \ + { \ + return netdev_led_attr_store(dev, buf, size, trigger); \ + } \ + static DEVICE_ATTR_RW(trigger_name) + +DEFINE_NETDEV_TRIGGER(link, TRIGGER_NETDEV_LINK); +DEFINE_NETDEV_TRIGGER(tx, TRIGGER_NETDEV_TX); +DEFINE_NETDEV_TRIGGER(rx, TRIGGER_NETDEV_RX); static ssize_t interval_show(struct device *dev, struct device_attribute *attr, char *buf)