On 6/13/07, Keiichi KII <k-keiichi@xxxxxxxxxxxxx> wrote:
> [...]
> +static DECLARE_MUTEX(netdev_change_sem);
The preferred style these days is to use a DEFINE_MUTEX
(and the struct mutex primitives) for such locks that are used
as binary semaphores.
BTW, a comment here to note what this lock protects is required.
[ You don't really need to give a comment for the target_list_lock
because it's defined just below the "target_list". It's not equally obvious
at first glance what is protected by the netdev_change_sem, however. ]
> +static int netconsole_event(struct notifier_block *this, unsigned long event,
> + void *ptr)
> +{
> + int error = 0;
> + unsigned long flags;
> + char *old_link_name = NULL, *new_link_name = NULL;
> + struct netconsole_target *nt, *tmp;
> + struct net_device *dev = ptr;
> + LIST_HEAD(modify_target_list);
> +
> + if (event == NETDEV_CHANGENAME) {
> + spin_lock_irqsave(&target_list_lock, flags);
> + list_for_each_entry_safe(nt, tmp, &target_list, list)
> + if (nt->np.dev == dev)
> + list_move(&nt->list, &modify_target_list);
> + spin_unlock_irqrestore(&target_list_lock, flags);
> + down(&netdev_change_sem);
> + list_for_each_entry(nt, &modify_target_list, list) {
> + [...]
> + }
> + up(&netdev_change_sem);
> + spin_lock_irqsave(&target_list_lock, flags);
> + list_for_each_entry_safe(nt, tmp, &modify_target_list, list)
> + list_move(&nt->list, &target_list);
> + spin_unlock_irqrestore(&target_list_lock, flags);
> + }
> +
> + return NOTIFY_DONE;
> +}
@@ -239,12 +240,14 @@ static void remove_target(struct netcons
{
unsigned long flags;
+ down(&netdev_change_sem);
spin_lock_irqsave(&target_list_lock, flags);
list_del(&nt->list);
if (list_empty(&target_list))
netpoll_cleanup(&nt->np);
spin_unlock_irqrestore(&target_list_lock, flags);
kfree(nt);
+ up(&netdev_change_sem);
}
+static char *make_netdev_class_name(char *netdev_name)
+{
+ char *name;
+
+ name = kasprintf(GFP_KERNEL, "net:%s", netdev_name);
+ if (!name) {
+ printk(KERN_ERR "netconsole: kmalloc() failed!\n");
+ return NULL;
+ }
+
+ return name;
+}
static int setup_target_sysfs(struct netconsole_target *nt)
{
+ int retval = 0;
+ char *name;
+
kobject_set_name(&nt->obj, "port%d", nt->id);
nt->obj.parent = &netconsole_miscdev.this_device->kobj;
nt->obj.ktype = &target_ktype;
- return kobject_register(&nt->obj);
+ retval = kobject_register(&nt->obj);
+ name = make_netdev_class_name(nt->np.dev_name);
+ if (!name)
+ return -ENOMEM;