Skip to contentSkip to conversation

sh: fix proc file removal for superh store queue

PATCH In review Neil Horman 3 participants 5 messages Aug 3, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sh: fix proc file removal for superh store queue

Patch to balance proc file creation and removal for superh store queue module. Currently a failure in module load, or a module unload leaves a proc file registered, causing an oops in the event the proc file is read. This patch corrects that.

Thanks & Regards
Neil

 sq.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
arch/sh/kernel/cpu/sh4/sq.c +10 -1
index 781dbb1..18b092c 100644
@@ -421,18 +421,27 @@ static struct miscdevice sq_dev = {
 
 static int __init sq_api_init(void)
 {
+	int ret;
 	printk(KERN_NOTICE "sq: Registering store queue API.\n");
 
 #ifdef CONFIG_PROC_FS
 	create_proc_read_entry("sq_mapping", 0, 0, sq_mapping_read_proc, 0);
 #endif
 
-	return misc_register(&sq_dev);
+	ret = misc_register(&sq_dev);
+#ifdef CONFIG_PROC_FS
+	if (ret) 
+		remove_proc_entry("sq_mapping", NULL);
+#endif
+	return ret;
 }
 
 static void __exit sq_api_exit(void)
 {
 	misc_deregister(&sq_dev);
+#ifdef CONFIG_PROC_FS
+	remove_proc_entry("sq_mapping", NULL);
+#endif
 }
 
 module_init(sq_api_init);

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#1 lore raw

Re: [KJ] [KJ PATCH] sh: fix proc file removal for superh store

Quoted 2 lines

To: [email protected]

An oops fix isn't a kernel-janitors thing. It's a slam-it-into-mainline-and-consider-a-backport thing.

Quoted 1 line · On Thu, 3 Aug 2006 15:18:28 -0400 Neil Horman <[email protected]> wrote:

Patch to balance proc file creation and removal for superh store queue module.

You have a superh machine?

Quoted 37 lines

Currently a failure in module load, or a module unload leaves a proc file registered, causing an oops in the event the proc file is read. This patch corrects that.

Thanks & Regards
Neil

 sq.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
arch/sh/kernel/cpu/sh4/sq.c +7 -1
index 781dbb1..18b092c 100644
@@ -421,18 +421,27 @@ static struct miscdevice sq_dev = {
 
 static int __init sq_api_init(void)
 {
+	int ret;
 	printk(KERN_NOTICE "sq: Registering store queue API.\n");
 
 #ifdef CONFIG_PROC_FS
 	create_proc_read_entry("sq_mapping", 0, 0, sq_mapping_read_proc, 0);
 #endif
 
-	return misc_register(&sq_dev);
+	ret = misc_register(&sq_dev);
+#ifdef CONFIG_PROC_FS
+	if (ret) 
+		remove_proc_entry("sq_mapping", NULL);
+#endif
+	return ret;
 }

arch/sh/kernel/cpu/sh4/sq.c static struct miscdevice sq_dev = { · line 447

Quoted 10 lines
arch/sh/kernel/cpu/sh4/sq.c +3 -0
 
 static void __exit sq_api_exit(void)
 {
 	misc_deregister(&sq_dev);
+#ifdef CONFIG_PROC_FS
+	remove_proc_entry("sq_mapping", NULL);
+#endif
 }
 
 module_init(sq_api_init);

OK. But we do have a stub which provides a CONFIG_PROC_FS=n implementation of remove_proc_entry(), so the ifdefs shouldn't be necessary?
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#2 lore raw

Re: [PATCH] sh: fix proc file removal for superh store queue module

Patch to clean up proc file removal in sq module for superh arch. currently on a failed module load or on module unload a proc file is left registered which can cause a random memory execution or oopses if read after unload. This patch cleans up that deregistration.

Thanks & Regards
Neil

 sq.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
arch/sh/kernel/cpu/sh4/sq.c +7 -3
index 781dbb1..4b2b0b1 100644
@@ -421,18 +421,22 @@ static struct miscdevice sq_dev = {
 
 static int __init sq_api_init(void)
 {
+	int ret;
 	printk(KERN_NOTICE "sq: Registering store queue API.\n");
 
-#ifdef CONFIG_PROC_FS
 	create_proc_read_entry("sq_mapping", 0, 0, sq_mapping_read_proc, 0);
-#endif
 
-	return misc_register(&sq_dev);
+	ret = misc_register(&sq_dev);
+	if (ret) 
+		remove_proc_entry("sq_mapping", NULL);
+
+	return ret;
 }
 
 static void __exit sq_api_exit(void)
 {
 	misc_deregister(&sq_dev);
+	remove_proc_entry("sq_mapping", NULL);
 }
 
 module_init(sq_api_init);

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

Acked-by
#3 lore raw

Re: [linuxsh-dev] [PATCH] sh: fix proc file removal for superh store queue module

Quoted 5 lines · Neil Horman

Patch to clean up proc file removal in sq module for superh arch. currently on a failed module load or on module unload a proc file is left registered which can cause a random memory execution or oopses if read after unload. This patch cleans up that deregistration.

Looks good, thanks Neil.

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#4 lore raw

Re: [KJ] [KJ PATCH] sh: fix proc file removal for superh store

In reply to Neil Horman
Quoted 6 lines · Andrew Morton
Quoted 2 lines

To: [email protected]

An oops fix isn't a kernel-janitors thing. It's a slam-it-into-mainline-and-consider-a-backport thing.

sorry, I was looking for more misc_register cleanups for KJ, and ran into this in the process. Wrote the email without thinking about the subject tags, my bad.

Quoted 7 lines
Quoted 1 line · On Thu, 3 Aug 2006 15:18:28 -0400 Neil Horman <[email protected]> wrote:

Patch to balance proc file creation and removal for superh store queue module.

You have a superh machine?

No, but the problem is fairly self evident. leaving a proc file dangling on module removal is begging to execute random data.

Quoted 3 lines

OK. But we do have a stub which provides a CONFIG_PROC_FS=n implementation of remove_proc_entry(), so the ifdefs shouldn't be necessary?

Good point, I'll remove, and repost.
Neil

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors