All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: net devices: Get network devices to show up in sysfs.
  2003-01-07 21:43 ` net devices: Get network devices to show up in sysfs Jeff Garzik
@ 2003-01-07 21:12   ` Patrick Mochel
  0 siblings, 0 replies; 2+ messages in thread
From: Patrick Mochel @ 2003-01-07 21:12 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Linux Kernel Mailing List


On Tue, 7 Jan 2003, Jeff Garzik wrote:

> On Mon, Jan 06, 2003 at 07:50:37PM +0000, Linux Kernel Mailing List wrote:
> > ChangeSet 1.838.151.11, 2003/01/06 13:50:37-06:00, mochel@osdl.org
> > 
> > 	net devices: Get network devices to show up in sysfs.
> > 	
> > 	- declare net_subsys, and register during net_dev_init().
> > 	- Add kobject to struct net_device.
> > 	- initialize name and register in register_netdevice().
> > 	- remove in unregister_netdevice().
> > 	
> > diff -Nru a/include/linux/netdevice.h b/include/linux/netdevice.h
> > --- a/include/linux/netdevice.h	Tue Jan  7 13:06:05 2003
> > +++ b/include/linux/netdevice.h	Tue Jan  7 13:06:05 2003
> > @@ -28,6 +28,7 @@
> >  #include <linux/if.h>
> >  #include <linux/if_ether.h>
> >  #include <linux/if_packet.h>
> > +#include <linux/kobject.h>
> >  
> >  #include <asm/atomic.h>
> >  #include <asm/cache.h>
> > @@ -438,6 +439,9 @@
> >  	/* this will get initialized at each interface type init routine */
> >  	struct divert_blk	*divert;
> >  #endif /* CONFIG_NET_DIVERT */
> > +
> > +	/* generic object representation */
> > +	struct kobject kobj;
> >  };
> 
> Just curious, is this needed purely for reference counting, or mainly to
> hook into sysfs?  If the former, net devices already have reference
> counting, so I want to make sure kobjects do not run afoul of that.

The latter. If desired, the reference counting can be converted to use 
kobject refcounting. I can look into this, if you like. 

> > +	snprintf(dev->kobj.name,KOBJ_NAME_LEN,dev->name);
> > +	kobj_set_kset_s(dev,net_subsys);
> > +	ret = kobject_register(&dev->kobj);
> 
> If the return code matters, shouldn't you be checking for its success?

Bah. How about the attached patch instead? 


	-pat

===== net/core/dev.c 1.51 vs edited =====
--- 1.51/net/core/dev.c	Mon Jan  6 13:50:36 2003
+++ edited/net/core/dev.c	Tue Jan  7 15:10:55 2003
@@ -2520,6 +2520,11 @@
 		if (d == dev || !strcmp(d->name, dev->name))
 			goto out_err;
 	}
+	snprintf(dev->kobj.name,KOBJ_NAME_LEN,dev->name);
+	kobj_set_kset_s(dev,net_subsys);
+	if ((ret = kobject_register(&dev->kobj)))
+		goto out_err;
+	
 	/*
 	 *	nil rebuild_header routine,
 	 *	that should be never called and used as just bug trap.
@@ -2547,10 +2552,7 @@
 	notifier_call_chain(&netdev_chain, NETDEV_REGISTER, dev);
 
 	net_run_sbin_hotplug(dev, "register");
-
-	snprintf(dev->kobj.name,KOBJ_NAME_LEN,dev->name);
-	kobj_set_kset_s(dev,net_subsys);
-	ret = kobject_register(&dev->kobj);
+	ret = 0;
 
 out:
 	return ret;


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: net devices: Get network devices to show up in sysfs.
       [not found] <200301072106.h07L63v29621@hera.kernel.org>
@ 2003-01-07 21:43 ` Jeff Garzik
  2003-01-07 21:12   ` Patrick Mochel
  0 siblings, 1 reply; 2+ messages in thread
From: Jeff Garzik @ 2003-01-07 21:43 UTC (permalink / raw)
  To: Linux Kernel Mailing List; +Cc: mochel

On Mon, Jan 06, 2003 at 07:50:37PM +0000, Linux Kernel Mailing List wrote:
> ChangeSet 1.838.151.11, 2003/01/06 13:50:37-06:00, mochel@osdl.org
> 
> 	net devices: Get network devices to show up in sysfs.
> 	
> 	- declare net_subsys, and register during net_dev_init().
> 	- Add kobject to struct net_device.
> 	- initialize name and register in register_netdevice().
> 	- remove in unregister_netdevice().
> 	
> diff -Nru a/include/linux/netdevice.h b/include/linux/netdevice.h
> --- a/include/linux/netdevice.h	Tue Jan  7 13:06:05 2003
> +++ b/include/linux/netdevice.h	Tue Jan  7 13:06:05 2003
> @@ -28,6 +28,7 @@
>  #include <linux/if.h>
>  #include <linux/if_ether.h>
>  #include <linux/if_packet.h>
> +#include <linux/kobject.h>
>  
>  #include <asm/atomic.h>
>  #include <asm/cache.h>
> @@ -438,6 +439,9 @@
>  	/* this will get initialized at each interface type init routine */
>  	struct divert_blk	*divert;
>  #endif /* CONFIG_NET_DIVERT */
> +
> +	/* generic object representation */
> +	struct kobject kobj;
>  };

Just curious, is this needed purely for reference counting, or mainly to
hook into sysfs?  If the former, net devices already have reference
counting, so I want to make sure kobjects do not run afoul of that.



> +static struct subsystem net_subsys;
> +
>  
>  /*******************************************************************************
>  
> @@ -2545,7 +2547,10 @@
>  	notifier_call_chain(&netdev_chain, NETDEV_REGISTER, dev);
>  
>  	net_run_sbin_hotplug(dev, "register");
> -	ret = 0;
> +
> +	snprintf(dev->kobj.name,KOBJ_NAME_LEN,dev->name);
> +	kobj_set_kset_s(dev,net_subsys);
> +	ret = kobject_register(&dev->kobj);

If the return code matters, shouldn't you be checking for its success?


> @@ -2671,6 +2676,8 @@
>  		goto out;
>  	}
>  
> +	kobject_unregister(&dev->kobj);
> +

...especially if kobject_register failed above

	Jeff




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-01-07 21:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <200301072106.h07L63v29621@hera.kernel.org>
2003-01-07 21:43 ` net devices: Get network devices to show up in sysfs Jeff Garzik
2003-01-07 21:12   ` Patrick Mochel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.