• Chris Wright's avatar
    [PATCH] Patch to hook up PPP to simple class sysfs support · 21601e2e
    Chris Wright authored
    * 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.
    21601e2e
ppp_generic.c 64.4 KB