Commit 21601e2e authored by Chris Wright's avatar Chris Wright Committed by Greg Kroah-Hartman

[PATCH] Patch to hook up PPP to simple class sysfs support

* Hanna Linder (hannal@us.ibm.com) wrote:
> +		ppp_class = class_simple_create(THIS_MODULE, "ppp");
> +		class_simple_device_add(ppp_class, MKDEV(PPP_MAJOR, 0), NULL, "ppp");

What happens if that class_simple_create() fails?  Actually,
class_simple_device_add could fail too, but doesn't seem anybody is
checking for that.

>  		err = devfs_mk_cdev(MKDEV(PPP_MAJOR, 0),
>  				S_IFCHR|S_IRUSR|S_IWUSR, "ppp");
> -		if (err)
> +		if (err) {
>  			unregister_chrdev(PPP_MAJOR, "ppp");
> +			class_simple_device_remove(MKDEV(PPP_MAJOR,0));
> +		}

need to destroy the class on error path to avoid leak.

> @@ -2540,6 +2547,7 @@ static void __exit ppp_cleanup(void)
>  	if (unregister_chrdev(PPP_MAJOR, "ppp") != 0)
>  		printk(KERN_ERR "PPP: failed to unregister PPP device\n");
>  	devfs_remove("ppp");
> +	class_simple_device_remove(MKDEV(PPP_MAJOR, 0));

ditto.  this will leak and would cause oops on reload of module.

something like below.
parent d5def5f7
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/rwsem.h> #include <linux/rwsem.h>
#include <linux/stddef.h> #include <linux/stddef.h>
#include <linux/device.h>
#include <net/slhc_vj.h> #include <net/slhc_vj.h>
#include <asm/atomic.h> #include <asm/atomic.h>
...@@ -271,6 +272,8 @@ static int ppp_connect_channel(struct channel *pch, int unit); ...@@ -271,6 +272,8 @@ static int ppp_connect_channel(struct channel *pch, int unit);
static int ppp_disconnect_channel(struct channel *pch); static int ppp_disconnect_channel(struct channel *pch);
static void ppp_destroy_channel(struct channel *pch); static void ppp_destroy_channel(struct channel *pch);
static struct class_simple *ppp_class;
/* Translates a PPP protocol number to a NP index (NP == network protocol) */ /* Translates a PPP protocol number to a NP index (NP == network protocol) */
static inline int proto_to_npindex(int proto) static inline int proto_to_npindex(int proto)
{ {
...@@ -804,15 +807,29 @@ static int __init ppp_init(void) ...@@ -804,15 +807,29 @@ static int __init ppp_init(void)
printk(KERN_INFO "PPP generic driver version " PPP_VERSION "\n"); printk(KERN_INFO "PPP generic driver version " PPP_VERSION "\n");
err = register_chrdev(PPP_MAJOR, "ppp", &ppp_device_fops); err = register_chrdev(PPP_MAJOR, "ppp", &ppp_device_fops);
if (!err) { if (!err) {
ppp_class = class_simple_create(THIS_MODULE, "ppp");
if (IS_ERR(ppp_class)) {
err = PTR_ERR(ppp_class);
goto out_chrdev;
}
class_simple_device_add(ppp_class, MKDEV(PPP_MAJOR, 0), NULL, "ppp");
err = devfs_mk_cdev(MKDEV(PPP_MAJOR, 0), err = devfs_mk_cdev(MKDEV(PPP_MAJOR, 0),
S_IFCHR|S_IRUSR|S_IWUSR, "ppp"); S_IFCHR|S_IRUSR|S_IWUSR, "ppp");
if (err) if (err)
unregister_chrdev(PPP_MAJOR, "ppp"); goto out_class;
} }
out:
if (err) if (err)
printk(KERN_ERR "failed to register PPP device (%d)\n", err); printk(KERN_ERR "failed to register PPP device (%d)\n", err);
return err; return err;
out_class:
class_simple_device_remove(MKDEV(PPP_MAJOR,0));
class_simple_destroy(ppp_class);
out_chrdev:
unregister_chrdev(PPP_MAJOR, "ppp");
goto out;
} }
/* /*
...@@ -2545,6 +2562,8 @@ static void __exit ppp_cleanup(void) ...@@ -2545,6 +2562,8 @@ static void __exit ppp_cleanup(void)
if (unregister_chrdev(PPP_MAJOR, "ppp") != 0) if (unregister_chrdev(PPP_MAJOR, "ppp") != 0)
printk(KERN_ERR "PPP: failed to unregister PPP device\n"); printk(KERN_ERR "PPP: failed to unregister PPP device\n");
devfs_remove("ppp"); devfs_remove("ppp");
class_simple_device_remove(MKDEV(PPP_MAJOR, 0));
class_simple_destroy(ppp_class);
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment