forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/arch/um/drivers/mconsole_kern.c
....@@ -1,7 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org)
34 * Copyright (C) 2001 - 2008 Jeff Dike (jdike@{addtoit,linux.intel}.com)
4
- * Licensed under the GPL
55 */
66
77 #include <linux/console.h>
....@@ -35,6 +35,8 @@
3535 #include "mconsole.h"
3636 #include "mconsole_kern.h"
3737 #include <os.h>
38
+
39
+static struct vfsmount *proc_mnt = NULL;
3840
3941 static int do_unlink_socket(struct notifier_block *notifier,
4042 unsigned long what, void *data)
....@@ -96,7 +98,6 @@
9698 }
9799 if (!list_empty(&mc_requests))
98100 schedule_work(&mconsole_work);
99
- reactivate_fd(fd, MCONSOLE_IRQ);
100101 return IRQ_HANDLED;
101102 }
102103
....@@ -124,7 +125,7 @@
124125
125126 void mconsole_proc(struct mc_request *req)
126127 {
127
- struct vfsmount *mnt = task_active_pid_ns(current)->proc_mnt;
128
+ struct vfsmount *mnt = proc_mnt;
128129 char *buf;
129130 int len;
130131 struct file *file;
....@@ -135,6 +136,10 @@
135136 ptr += strlen("proc");
136137 ptr = skip_spaces(ptr);
137138
139
+ if (!mnt) {
140
+ mconsole_reply(req, "Proc not available", 1, 0);
141
+ goto out;
142
+ }
138143 file = file_open_root(mnt->mnt_root, mnt, ptr, O_RDONLY, 0);
139144 if (IS_ERR(file)) {
140145 mconsole_reply(req, "Failed to open file", 1, 0);
....@@ -218,7 +223,7 @@
218223
219224 void mconsole_stop(struct mc_request *req)
220225 {
221
- deactivate_fd(req->originating_fd, MCONSOLE_IRQ);
226
+ block_signals();
222227 os_set_fd_block(req->originating_fd, 1);
223228 mconsole_reply(req, "stopped", 0, 0);
224229 for (;;) {
....@@ -240,8 +245,8 @@
240245 (*req->cmd->handler)(req);
241246 }
242247 os_set_fd_block(req->originating_fd, 0);
243
- reactivate_fd(req->originating_fd, MCONSOLE_IRQ);
244248 mconsole_reply(req, "", 0, 0);
249
+ unblock_signals();
245250 }
246251
247252 static DEFINE_SPINLOCK(mc_devices_lock);
....@@ -644,7 +649,7 @@
644649 {
645650 struct task_struct *task = arg;
646651
647
- show_stack(task, NULL);
652
+ show_stack(task, NULL, KERN_INFO);
648653 }
649654
650655 /*
....@@ -685,6 +690,24 @@
685690 with_console(req, stack_proc, to);
686691 }
687692
693
+static int __init mount_proc(void)
694
+{
695
+ struct file_system_type *proc_fs_type;
696
+ struct vfsmount *mnt;
697
+
698
+ proc_fs_type = get_fs_type("proc");
699
+ if (!proc_fs_type)
700
+ return -ENODEV;
701
+
702
+ mnt = kern_mount(proc_fs_type);
703
+ put_filesystem(proc_fs_type);
704
+ if (IS_ERR(mnt))
705
+ return PTR_ERR(mnt);
706
+
707
+ proc_mnt = mnt;
708
+ return 0;
709
+}
710
+
688711 /*
689712 * Changed by mconsole_setup, which is __setup, and called before SMP is
690713 * active.
....@@ -697,6 +720,8 @@
697720 long sock;
698721 int err;
699722 char file[UNIX_PATH_MAX];
723
+
724
+ mount_proc();
700725
701726 if (umid_file_name("mconsole", file, sizeof(file)))
702727 return -1;
....@@ -754,10 +779,9 @@
754779 return count;
755780 }
756781
757
-static const struct file_operations mconsole_proc_fops = {
758
- .owner = THIS_MODULE,
759
- .write = mconsole_proc_write,
760
- .llseek = noop_llseek,
782
+static const struct proc_ops mconsole_proc_ops = {
783
+ .proc_write = mconsole_proc_write,
784
+ .proc_lseek = noop_llseek,
761785 };
762786
763787 static int create_proc_mconsole(void)
....@@ -767,7 +791,7 @@
767791 if (notify_socket == NULL)
768792 return 0;
769793
770
- ent = proc_create("mconsole", 0200, NULL, &mconsole_proc_fops);
794
+ ent = proc_create("mconsole", 0200, NULL, &mconsole_proc_ops);
771795 if (ent == NULL) {
772796 printk(KERN_INFO "create_proc_mconsole : proc_create failed\n");
773797 return 0;