Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp539291pxb; Thu, 31 Mar 2022 11:04:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGr0Ukx779Az9OpiSN8JK/IRxrCZWBsoHeX5mbGaylBBTBNuYfacjfaNZBMTRN3GR7D+rA X-Received: by 2002:a4a:ad46:0:b0:324:498e:4fe1 with SMTP id s6-20020a4aad46000000b00324498e4fe1mr5533360oon.89.1648749860289; Thu, 31 Mar 2022 11:04:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648749860; cv=none; d=google.com; s=arc-20160816; b=rEGFhu7/fRqYh+8glqiedlGkR13j08nW9WxpoJdBGPcLqFHcfuVVJSgh+n1NfmMahj jKx05LuL5e16bxWL/0CF+P5LStt6pZUCYb5g1AR1w0kmNfYLccAlRDs2W46Mzutb1LuP 8cDZ7yLxK2iQDxMihLVw5/uWCekOufYhTCIGB1itb0FLdsd9gwJfaV4q6+VPERibN1Vt 8P55BvI0QZNyt7YgmnuU3RIZPIrA0DRTspKO4351sYvmeN1sYeBxbf4KGFJMaZgHCAHP dzyCE1WXMUM4fhiJZJ/z170qc/DWdRahXYamBQRt4z++fwoeUsmTNQiHSNPR4ftchGwx OwkQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Tz1+jyzSmP98e5ooAatmzdnU3iInwBIM2H0hqBxqsjQ=; b=f5GrQyryJVG71JibGbFSGKsQ93mX6CCByo8dtcmevAiv0otnQgQ8p+yNjQG0Ddjioa BLi7ODXAm8ko9CY8paByPrlCDePmNijsXh+d2Bv0lNkQWOTZ/9VFzM1UnxqS5w6U631a 5Xj33y2ty4g7O7R1xl630lX+C0oe902jzA6g1o9BJmdmBGq9200m8yIHyQrz18QJiDmL SDqH8ffKRAFT5+z2t2r2kTvECF6Qu9d+CDEea9TyjrzrE+4UQfrd+nVop3+ID5rw8SmE 2Qng4F6nhQ4dulIGH+Y+kp9AO5B2HW0DzXgQ5pYUsdnwgx8KAVi38+xihEOSRO09YOFy bnBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=psM+ebjR; 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=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x18-20020a05683000d200b005cb2fc1387dsi44838oto.249.2022.03.31.11.04.06; Thu, 31 Mar 2022 11:04:20 -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=@163.com header.s=s110527 header.b=psM+ebjR; 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=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238099AbiCaPSc (ORCPT + 99 others); Thu, 31 Mar 2022 11:18:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238016AbiCaPSa (ORCPT ); Thu, 31 Mar 2022 11:18:30 -0400 Received: from m12-15.163.com (m12-15.163.com [220.181.12.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 656D2211ECF for ; Thu, 31 Mar 2022 08:16:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=Tz1+j yzSmP98e5ooAatmzdnU3iInwBIM2H0hqBxqsjQ=; b=psM+ebjRvi0rA8IRmjsJy 5kvMXiucEUqKbJzipWmIfwEijotiVEwkdZSpGwwrPkBxW0ykRt/F6uWsT+xRo3DN qrRrtVBNIAtrX+2HphE6ucFZOSliaypCnfLob8ngiYLoygrXQ7Z/3MqG+uscGwXh KrHd0jy+ksCLtDkNX6q4r8= Received: from localhost (unknown [119.123.75.76]) by smtp11 (Coremail) with SMTP id D8CowABHgXyzxUViQeNcAQ--.3707S2; Thu, 31 Mar 2022 23:16:04 +0800 (CST) From: wujunwen To: arnd@arndb.de, gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, wujunwen Subject: [PATCH v2] char: misc:use DEFINE_PROC_SHOW_ATTRIBUTE micro to simplify misc proc_fops Date: Thu, 31 Mar 2022 15:15:57 +0000 Message-Id: <20220331151557.3946-1-wudaemon@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: D8CowABHgXyzxUViQeNcAQ--.3707S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxWrW5Zw1fAFy5tFWxKF17KFg_yoW5Wr48pF 4fZ347JF4UJF4xWrW3ta1DuF9IqFn7Xa4q9rnrG3yfZF1DZr12gF1DAa47ZFy5G3ykWrnx XFs0kry5Cw1jy3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pEAhLnUUUUU= X-Originating-IP: [119.123.75.76] X-CM-SenderInfo: 5zxgtvxprqqiywtou0bp/1tbiLBTUbVspdNuNnQAAsM 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 DEFINE_PROC_SHOW_ATTRIBUTE is used to simply seq_file flow ,so we can use it to simplify misc proc_fops. Signed-off-by: wujunwen --- V1 -> V2: Fix compile error with no "CONFIG_PROC_FS" drivers/char/misc.c | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/drivers/char/misc.c b/drivers/char/misc.c index ca5141ed5ef3..076b7f08aa7a 100644 --- a/drivers/char/misc.c +++ b/drivers/char/misc.c @@ -64,40 +64,23 @@ static DEFINE_MUTEX(misc_mtx); static DECLARE_BITMAP(misc_minors, DYNAMIC_MINORS); #ifdef CONFIG_PROC_FS -static void *misc_seq_start(struct seq_file *seq, loff_t *pos) -{ - mutex_lock(&misc_mtx); - return seq_list_start(&misc_list, *pos); -} -static void *misc_seq_next(struct seq_file *seq, void *v, loff_t *pos) +static int misc_show(struct seq_file *seq, void *v) { - return seq_list_next(v, &misc_list, pos); -} + const struct miscdevice *p; -static void misc_seq_stop(struct seq_file *seq, void *v) -{ + mutex_lock(&misc_mtx); + list_for_each_entry(p, &misc_list, list) { + seq_printf(seq, "%3i %s\n", p->minor, p->name ? p->name : ""); + } mutex_unlock(&misc_mtx); -} - -static int misc_seq_show(struct seq_file *seq, void *v) -{ - const struct miscdevice *p = list_entry(v, struct miscdevice, list); - - seq_printf(seq, "%3i %s\n", p->minor, p->name ? p->name : ""); return 0; } - -static const struct seq_operations misc_seq_ops = { - .start = misc_seq_start, - .next = misc_seq_next, - .stop = misc_seq_stop, - .show = misc_seq_show, -}; +DEFINE_PROC_SHOW_ATTRIBUTE(misc); #endif -static int misc_open(struct inode *inode, struct file *file) +static int misc_fops_open(struct inode *inode, struct file *file) { int minor = iminor(inode); struct miscdevice *c; @@ -148,7 +131,7 @@ static struct class *misc_class; static const struct file_operations misc_fops = { .owner = THIS_MODULE, - .open = misc_open, + .open = misc_fops_open, .llseek = noop_llseek, }; @@ -266,9 +249,11 @@ static char *misc_devnode(struct device *dev, umode_t *mode) static int __init misc_init(void) { int err; +#ifdef CONFIG_PROC_FS struct proc_dir_entry *ret; - ret = proc_create_seq("misc", 0, NULL, &misc_seq_ops); + ret = proc_create("misc", 0, NULL, &misc_proc_ops); +#endif misc_class = class_create(THIS_MODULE, "misc"); err = PTR_ERR(misc_class); if (IS_ERR(misc_class)) @@ -284,8 +269,10 @@ static int __init misc_init(void) pr_err("unable to get major %d for misc devices\n", MISC_MAJOR); class_destroy(misc_class); fail_remove: +#ifdef CONFIG_PROC_FS if (ret) remove_proc_entry("misc", NULL); +#endif return err; } subsys_initcall(misc_init); -- 2.25.1