From patchwork Sun Dec 2 08:33:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Lee X-Patchwork-Id: 1006447 X-Patchwork-Delegate: boris.brezillon@free-electrons.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gAqfYYio"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="q2PXT1U8"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4371dM5H2Sz9sCQ for ; Sun, 2 Dec 2018 19:34:27 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=ysPoxA2lOQ649wwLZk8IFhRxB9o7LjobeZcBZLysJHw=; b=gAq fYYioZS8pb3I/W7a7oK6iJbNcvBEsuqqcp5fY1WhghP+oNDOX0pxjebOtKp5H8AMvOknDeplsvmii QNNMFT07Ip2R4z0RenM8xIwl0lhQI0AW5q0g0cpMc/Prw0GzBX69F4NIkKtYsgscweN0ou1Xtuci0 cFVY6qJdWQBAzg/DxpoMa8uv14OADpN/8HgCHUV5BPF+p9eioLIgTQfvVvcKI4u/DhZ8uCOXO1Na7 8zKb+/dFC7I8/NDKhVhxiC+wz8L9OPYCoLWdTD+rat/ZihmGO//HbkCsuaQiTiKGZwhVHrc0YJHpu ufLI2Qy1CQK839xhYMKcryBIbkt4gPg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gTNCl-0003wE-7i; Sun, 02 Dec 2018 08:34:19 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gTNCi-0003vA-DW for linux-mtd@lists.infradead.org; Sun, 02 Dec 2018 08:34:17 +0000 Received: by mail-pf1-x444.google.com with SMTP id c123so4870722pfb.0 for ; Sun, 02 Dec 2018 00:34:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=wueTmP8apvZBSrrpJh/dUcWLiev/DbStDQlMrgptmPQ=; b=q2PXT1U8kh1bt5I18t4vCunMZxsx6qkn1/EyojXRmRhmbg4wF6YCsNeD+oaDm3xQ9a b+d9LKrdL3cCzDe8kQpPBxdykKRoy/+u75AV7nl7IlpAS3z63yUe0X55ZJzVvwF6ESq+ SAIPl+woWKivLkmcjEj1XXTROBShYw9Evo8q4wRx3BRNtzLikqjsqhDDq2N9RPbJCCMG gGpt8Px6kykVx2ipu66UPzU1l9nmj8J5lnwuLVrEyucxd1jarugV2N4DsZuRE/TWH6j9 ggkn4ib980KRN0zZx38bgcF6ooquRWM+rbIj35Z9/joqmZFq9GT8OSzTDO0/AHFdAWC3 U1XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=wueTmP8apvZBSrrpJh/dUcWLiev/DbStDQlMrgptmPQ=; b=noV3YZH+hYJFBM2ehvMLDXZHKiOP7KAGMfHHdMjqwlz0OWyNhOuLgXqVQJ8v68OR5M /36ta4ylfozs6q3uw8okxYAhHGM/ewjPRnvNPvLbXuZ2NSiX+uc/LGQDUbqOL/0gvI4Z q6scmgc7qdoT7Of6qjtd3EoWP4aTdpbJ6gQsUCEwelSeApn4S9ckcMkomxFUeCzSLBya VLiS2+njMzITB5Hlkaf5jQOpSNcFW8BDL6BMa+e5SJpeZpjGDmgjWmdyjsFqMzTPaHtx PFwk9LGnM+6h3o94dHISchvGr7WIBwkF8qPTV2rmIK/o4WS0P49aamY/u2SxGJHz/w84 NSew== X-Gm-Message-State: AA+aEWY1yfYDFKmv9B6NKq2Rckdi7LvkMHO0/lEvBvwOzzIUQx/M3aeC UJ+frNUq6IhK6OvOEpB5KSc= X-Google-Smtp-Source: AFSGD/UHoAmmbLjiwaTh2unsBwXvJhO7HrDyzw9FXDR9z3a3JbWUfn8/8ERycvFvIbMUmQEKKAL1sw== X-Received: by 2002:a63:6cc8:: with SMTP id h191mr9382653pgc.366.1543739640690; Sun, 02 Dec 2018 00:34:00 -0800 (PST) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id v62sm18814570pfd.163.2018.12.02.00.33.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 02 Dec 2018 00:33:59 -0800 (PST) From: Yangtao Li To: robert.jarzmik@free.fr, dwmw2@infradead.org, computersforpeace@gmail.com, boris.brezillon@bootlin.com, marek.vasut@gmail.com, richard@nod.at, miquel.raynal@bootlin.com, keescook@chromium.org, shreeya.patel23498@gmail.com Subject: [PATCH] mtd: use DEFINE_SHOW_ATTRIBUTE() instead of open-coding it Date: Sun, 2 Dec 2018 03:33:58 -0500 Message-Id: <20181202083358.10896-1-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181202_003416_475929_747474F9 X-CRM114-Status: GOOD ( 13.12 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:444 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (tiny.windzz[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yangtao Li , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org DEFINE_SHOW_ATTRIBUTE macro can help us simplify the code,so change to it.And change the DEBUGFS_RO_ATTR macro defined in some file to a standard macro. Signed-off-by: Yangtao Li --- drivers/mtd/devices/docg3.c | 16 ++++++++-------- drivers/mtd/devices/docg3.h | 11 ----------- drivers/mtd/mtdswap.c | 13 +------------ drivers/mtd/nand/raw/nandsim.c | 17 +++-------------- 4 files changed, 12 insertions(+), 45 deletions(-) diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index 512bd4c2eec0..4c94fc096696 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -1603,7 +1603,7 @@ static void doc_unregister_sysfs(struct platform_device *pdev, /* * Debug sysfs entries */ -static int dbg_flashctrl_show(struct seq_file *s, void *p) +static int flashcontrol_show(struct seq_file *s, void *p) { struct docg3 *docg3 = (struct docg3 *)s->private; @@ -1623,9 +1623,9 @@ static int dbg_flashctrl_show(struct seq_file *s, void *p) return 0; } -DEBUGFS_RO_ATTR(flashcontrol, dbg_flashctrl_show); +DEFINE_SHOW_ATTRIBUTE(flashcontrol); -static int dbg_asicmode_show(struct seq_file *s, void *p) +static int asic_mode_show(struct seq_file *s, void *p) { struct docg3 *docg3 = (struct docg3 *)s->private; @@ -1660,9 +1660,9 @@ static int dbg_asicmode_show(struct seq_file *s, void *p) seq_puts(s, ")\n"); return 0; } -DEBUGFS_RO_ATTR(asic_mode, dbg_asicmode_show); +DEFINE_SHOW_ATTRIBUTE(asic_mode); -static int dbg_device_id_show(struct seq_file *s, void *p) +static int device_id_show(struct seq_file *s, void *p) { struct docg3 *docg3 = (struct docg3 *)s->private; int id; @@ -1674,9 +1674,9 @@ static int dbg_device_id_show(struct seq_file *s, void *p) seq_printf(s, "DeviceId = %d\n", id); return 0; } -DEBUGFS_RO_ATTR(device_id, dbg_device_id_show); +DEFINE_SHOW_ATTRIBUTE(device_id); -static int dbg_protection_show(struct seq_file *s, void *p) +static int protection_show(struct seq_file *s, void *p) { struct docg3 *docg3 = (struct docg3 *)s->private; int protect, dps0, dps0_low, dps0_high, dps1, dps1_low, dps1_high; @@ -1726,7 +1726,7 @@ static int dbg_protection_show(struct seq_file *s, void *p) !!(dps1 & DOC_DPS_KEY_OK)); return 0; } -DEBUGFS_RO_ATTR(protection, dbg_protection_show); +DEFINE_SHOW_ATTRIBUTE(protection); static void __init doc_dbg_register(struct mtd_info *floor) { diff --git a/drivers/mtd/devices/docg3.h b/drivers/mtd/devices/docg3.h index e99946575398..e16dca23655b 100644 --- a/drivers/mtd/devices/docg3.h +++ b/drivers/mtd/devices/docg3.h @@ -317,17 +317,6 @@ struct docg3 { #define doc_info(fmt, arg...) dev_info(docg3->dev, (fmt), ## arg) #define doc_dbg(fmt, arg...) dev_dbg(docg3->dev, (fmt), ## arg) #define doc_vdbg(fmt, arg...) dev_vdbg(docg3->dev, (fmt), ## arg) - -#define DEBUGFS_RO_ATTR(name, show_fct) \ - static int name##_open(struct inode *inode, struct file *file) \ - { return single_open(file, show_fct, inode->i_private); } \ - static const struct file_operations name##_fops = { \ - .owner = THIS_MODULE, \ - .open = name##_open, \ - .llseek = seq_lseek, \ - .read = seq_read, \ - .release = single_release \ - }; #endif /* diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c index d9dcb2d051b4..d162d1717fad 100644 --- a/drivers/mtd/mtdswap.c +++ b/drivers/mtd/mtdswap.c @@ -1265,18 +1265,7 @@ static int mtdswap_show(struct seq_file *s, void *data) return 0; } - -static int mtdswap_open(struct inode *inode, struct file *file) -{ - return single_open(file, mtdswap_show, inode->i_private); -} - -static const struct file_operations mtdswap_fops = { - .open = mtdswap_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; +DEFINE_SHOW_ATTRIBUTE(mtdswap); static int mtdswap_add_debugfs(struct mtdswap_dev *d) { diff --git a/drivers/mtd/nand/raw/nandsim.c b/drivers/mtd/nand/raw/nandsim.c index c452819f6123..ef8721418f2d 100644 --- a/drivers/mtd/nand/raw/nandsim.c +++ b/drivers/mtd/nand/raw/nandsim.c @@ -443,7 +443,7 @@ static unsigned long total_wear = 0; /* MTD structure for NAND controller */ static struct mtd_info *nsmtd; -static int nandsim_debugfs_show(struct seq_file *m, void *private) +static int nandsim_show(struct seq_file *m, void *private) { unsigned long wmin = -1, wmax = 0, avg; unsigned long deciles[10], decile_max[10], tot = 0; @@ -494,18 +494,7 @@ static int nandsim_debugfs_show(struct seq_file *m, void *private) return 0; } - -static int nandsim_debugfs_open(struct inode *inode, struct file *file) -{ - return single_open(file, nandsim_debugfs_show, inode->i_private); -} - -static const struct file_operations dfs_fops = { - .open = nandsim_debugfs_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; +DEFINE_SHOW_ATTRIBUTE(nandsim); /** * nandsim_debugfs_create - initialize debugfs @@ -531,7 +520,7 @@ static int nandsim_debugfs_create(struct nandsim *dev) } dent = debugfs_create_file("nandsim_wear_report", S_IRUSR, - root, dev, &dfs_fops); + root, dev, &nandsim_fops); if (IS_ERR_OR_NULL(dent)) { NS_ERR("cannot create \"nandsim_wear_report\" debugfs entry\n"); return -1;