tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[no subject]



>  
>  /*
> + * Convert major number to device driver name.
> + */
> +const char *
> +devsw_getname(devmajor_t major)
> +{
> +     const char *name;
> +     int i;
> +
> +     name = NULL;
> +
> +     mutex_enter(&device_lock);
> +     if (major < 0) {
> +             mutex_exit(&device_lock);
> +             return (NULL);
> +     }

No need to acquire lock to test argument.  The reason the code you
refer did is it accesses global variables, i guess.

> +     for (i = 0 ; i < max_devsw_convs; i++) {
> +             if (devsw_conv[i].d_cmajor == major ||
> +                 devsw_conv[i].d_bmajor == major ) {
> +                     name = devsw_conv[i].d_name;
> +                     break;
> +             }
> +     }
> +     mutex_exit(&device_lock);
> +     return (name);
> +}

        :

> +             do {
> +                     if (cdevsw_lookup(dev) == NULL) {
> +                             /* Get device name from devsw_conv array */
> +                             if ((name = devsw_getname(major(dev))) == NULL)
> +                                     break;
> +                     
> +                             /* Try to autoload device module */
> +                             mutex_enter(&module_lock);
> +                             gen = module_gen;
> +                             (void) module_autoload(name, 
> MODULE_CLASS_DRIVER);
> +                             mutex_exit(&module_lock);
> +                     } else
> +                             break;
> +             } while (gen != module_gen);

I prefer to invert condition to make less indentaion. i.e.,


        do {
                /* Device already exists. */
                if (cdevsw_lookup() != NULL)
                        break;

                /* Get device name from devsw_conv array */
                if ((name = ...
                        break;

                   :
                mutex_exit(&module_lock);
        } while (gen != module_gen);

enami.


Home | Main Index | Thread Index | Old Index