Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fbdev/core: Move procfs code to separate file

Move fbdev's procfs code into a separate file and contain it in
init and cleanup helpers. For the cleanup, replace remove_proc_entry()
with proc_remove(). It is equivalent in functionality, but looks
more like an inverse of proc_create_seq().

v2:
* document proc_remove() usage (Sam)
* revert unrelated removal of for_each_registered_fb()

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20230613110953.24176-36-tzimmermann@suse.de

+80 -43
+1
drivers/video/fbdev/core/Makefile
··· 3 3 obj-$(CONFIG_FB) += fb.o 4 4 fb-y := fb_backlight.o \ 5 5 fb_info.o \ 6 + fb_procfs.o \ 6 7 fbmem.o fbmon.o fbcmap.o fbsysfs.o \ 7 8 modedb.o fbcvt.o fb_cmdline.o fb_io_fops.o 8 9 fb-$(CONFIG_FB_DEFERRED_IO) += fb_defio.o
+11 -1
drivers/video/fbdev/core/fb_internal.h
··· 3 3 #ifndef _FB_INTERNAL_H 4 4 #define _FB_INTERNAL_H 5 5 6 - struct fb_info; 6 + #include <linux/fb.h> 7 + #include <linux/mutex.h> 8 + 9 + /* fbmem.c */ 10 + extern struct mutex registration_lock; 11 + extern struct fb_info *registered_fb[FB_MAX]; 12 + extern int num_registered_fb; 13 + 14 + /* fb_procfs.c */ 15 + int fb_init_procfs(void); 16 + void fb_cleanup_procfs(void); 7 17 8 18 /* fbsysfs.c */ 9 19 int fb_device_create(struct fb_info *fb_info);
+62
drivers/video/fbdev/core/fb_procfs.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include <linux/proc_fs.h> 4 + 5 + #include "fb_internal.h" 6 + 7 + static struct proc_dir_entry *fb_proc_dir_entry; 8 + 9 + static void *fb_seq_start(struct seq_file *m, loff_t *pos) 10 + { 11 + mutex_lock(&registration_lock); 12 + 13 + return (*pos < FB_MAX) ? pos : NULL; 14 + } 15 + 16 + static void fb_seq_stop(struct seq_file *m, void *v) 17 + { 18 + mutex_unlock(&registration_lock); 19 + } 20 + 21 + static void *fb_seq_next(struct seq_file *m, void *v, loff_t *pos) 22 + { 23 + (*pos)++; 24 + 25 + return (*pos < FB_MAX) ? pos : NULL; 26 + } 27 + 28 + static int fb_seq_show(struct seq_file *m, void *v) 29 + { 30 + int i = *(loff_t *)v; 31 + struct fb_info *fi = registered_fb[i]; 32 + 33 + if (fi) 34 + seq_printf(m, "%d %s\n", fi->node, fi->fix.id); 35 + 36 + return 0; 37 + } 38 + 39 + static const struct seq_operations __maybe_unused fb_proc_seq_ops = { 40 + .start = fb_seq_start, 41 + .stop = fb_seq_stop, 42 + .next = fb_seq_next, 43 + .show = fb_seq_show, 44 + }; 45 + 46 + int fb_init_procfs(void) 47 + { 48 + struct proc_dir_entry *proc; 49 + 50 + proc = proc_create_seq("fb", 0, NULL, &fb_proc_seq_ops); 51 + if (!proc) 52 + return -ENOMEM; 53 + 54 + fb_proc_dir_entry = proc; 55 + 56 + return 0; 57 + } 58 + 59 + void fb_cleanup_procfs(void) 60 + { 61 + proc_remove(fb_proc_dir_entry); 62 + }
+6 -42
drivers/video/fbdev/core/fbmem.c
··· 24 24 #include <linux/vt.h> 25 25 #include <linux/init.h> 26 26 #include <linux/linux_logo.h> 27 - #include <linux/proc_fs.h> 28 27 #include <linux/platform_device.h> 29 - #include <linux/seq_file.h> 30 28 #include <linux/console.h> 31 29 #include <linux/kmod.h> 32 30 #include <linux/err.h> ··· 46 48 47 49 #define FBPIXMAPSIZE (1024 * 8) 48 50 49 - static DEFINE_MUTEX(registration_lock); 50 - 51 + DEFINE_MUTEX(registration_lock); 51 52 struct fb_info *registered_fb[FB_MAX] __read_mostly; 52 53 int num_registered_fb __read_mostly; 53 54 #define for_each_registered_fb(i) \ ··· 701 704 #endif /* CONFIG_LOGO */ 702 705 EXPORT_SYMBOL(fb_prepare_logo); 703 706 EXPORT_SYMBOL(fb_show_logo); 704 - 705 - static void *fb_seq_start(struct seq_file *m, loff_t *pos) 706 - { 707 - mutex_lock(&registration_lock); 708 - return (*pos < FB_MAX) ? pos : NULL; 709 - } 710 - 711 - static void *fb_seq_next(struct seq_file *m, void *v, loff_t *pos) 712 - { 713 - (*pos)++; 714 - return (*pos < FB_MAX) ? pos : NULL; 715 - } 716 - 717 - static void fb_seq_stop(struct seq_file *m, void *v) 718 - { 719 - mutex_unlock(&registration_lock); 720 - } 721 - 722 - static int fb_seq_show(struct seq_file *m, void *v) 723 - { 724 - int i = *(loff_t *)v; 725 - struct fb_info *fi = registered_fb[i]; 726 - 727 - if (fi) 728 - seq_printf(m, "%d %s\n", fi->node, fi->fix.id); 729 - return 0; 730 - } 731 - 732 - static const struct seq_operations __maybe_unused proc_fb_seq_ops = { 733 - .start = fb_seq_start, 734 - .next = fb_seq_next, 735 - .stop = fb_seq_stop, 736 - .show = fb_seq_show, 737 - }; 738 707 739 708 /* 740 709 * We hold a reference to the fb_info in file->private_data, ··· 1587 1624 { 1588 1625 int ret; 1589 1626 1590 - if (!proc_create_seq("fb", 0, NULL, &proc_fb_seq_ops)) 1591 - return -ENOMEM; 1627 + ret = fb_init_procfs(); 1628 + if (ret) 1629 + return ret; 1592 1630 1593 1631 ret = register_chrdev(FB_MAJOR, "fb", &fb_fops); 1594 1632 if (ret) { ··· 1612 1648 err_class: 1613 1649 unregister_chrdev(FB_MAJOR, "fb"); 1614 1650 err_chrdev: 1615 - remove_proc_entry("fb", NULL); 1651 + fb_cleanup_procfs(); 1616 1652 return ret; 1617 1653 } 1618 1654 ··· 1623 1659 { 1624 1660 fb_console_exit(); 1625 1661 1626 - remove_proc_entry("fb", NULL); 1662 + fb_cleanup_procfs(); 1627 1663 class_destroy(fb_class); 1628 1664 unregister_chrdev(FB_MAJOR, "fb"); 1629 1665 }