Changeset 5f6e25e in mainline for uspace/drv/char/ns8250/ns8250.c


Ignore:
Timestamp:
2011-08-29T23:00:12Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
58cbb0c8
Parents:
c5be39b
Message:

Leave it up to DDF to free driver-specific data. This makes it possible
to ensure soft state is not freed during calls to driver entry points.

This requires some driver changes:

  • minimum change is not to free() driver-data structures (ddf_fun_t.driver_data and ddf_dev_t.driver_data)
  • ideally allocate using ddf_dev_data_alloc(), ddf_fun_data_alloc()

I tried fixing existing drivers accordingly (mostly the minimalistic
change variant), but could have missed something.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/char/ns8250/ns8250.c

    rc5be39b r5f6e25e  
    112112        fibril_mutex_t mutex;
    113113} ns8250_t;
    114 
    115 /** Create per-device soft-state structure.
    116  *
    117  * @return      Pointer to soft-state structure.
    118  */
    119 static ns8250_t *ns8250_new(void)
    120 {
    121         ns8250_t *ns;
    122        
    123         ns = (ns8250_t *) calloc(1, sizeof(ns8250_t));
    124         if (ns == NULL)
    125                 return NULL;
    126        
    127         fibril_mutex_initialize(&ns->mutex);
    128         return ns;
    129 }
    130 
    131 /** Delete soft-state structure.
    132  *
    133  * @param ns    The driver data structure.
    134  */
    135 static void ns8250_delete(ns8250_t *ns)
    136 {
    137         assert(ns != NULL);
    138         free(ns);
    139 }
    140114
    141115/** Find out if there is some incomming data available on the serial port.
     
    721695       
    722696        /* Allocate soft-state for the device */
    723         ns = ns8250_new();
     697        ns = ddf_dev_data_alloc(dev, sizeof(ns8250_t));
    724698        if (ns == NULL) {
    725699                rc = ENOMEM;
     
    727701        }
    728702       
     703        fibril_mutex_initialize(&ns->mutex);
    729704        ns->dev = dev;
    730         dev->driver_data = ns;
    731705       
    732706        rc = ns8250_dev_initialize(ns);
     
    792766        if (need_cleanup)
    793767                ns8250_dev_cleanup(ns);
    794         if (ns != NULL)
    795                 ns8250_delete(ns);
    796768        return rc;
    797769}
Note: See TracChangeset for help on using the changeset viewer.