openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/sysfsutils/2.1.0-r5/sysfsutils-2.1.0/lib/sysfs_driver.c
struct dlist* sysfs_get_driver_devices(struct sysfs_driver* drv)
{
    char* ln = NULL;
    struct dlist* linklist = NULL;
    struct sysfs_device* dev = NULL;

    if (!drv)
    {
        errno = EINVAL;
        return NULL;
    }

    linklist = read_dir_links(drv->path);
    if (linklist)
    {
        dlist_for_each_data(linklist, ln, char)
        {

            if (!strncmp(ln, SYSFS_MODULE_NAME, strlen(ln)))
                continue;

            dev = sysfs_open_device(drv->bus, ln);
            if (!dev)
            {
                dprintf("Error opening driver's device\n");
                sysfs_close_list(linklist);
                return NULL;
            }
            if (!drv->devices)
            {
                drv->devices = dlist_new_with_delete(
                    sizeof(struct sysfs_device), sysfs_close_driver_device);
                if (!drv->devices)
                {
                    dprintf("Error creating device list\n");
                    sysfs_close_list(linklist);
                    return NULL;
                }
            }
            dlist_unshift_sorted(drv->devices, dev, sort_list);
        }
        sysfs_close_list(linklist);
    }
    return drv->devices;
}
/**
 * sysfs_get_driver_devices: gets list of devices that use the driver
 * @drv: sysfs_driver whose device list is needed
 * Returns dlist of struct sysfs_device on success and NULL on failure
 */
gets list of devices that use the driver
@drv: sysfs_driver whose device list is needed
Returns dlist of struct sysfs_device on success and NULL on failure
gets list of devices that use the driver @drv : sysfs_driver whose device list is needed Returns dlist of struct sysfs_device on success and NULL on failure
struct dlist* sysfs_get_driver_devices(struct sysfs_driver* drv)
{
    char* ln = NULL;
    struct dlist* linklist = NULL;
    struct sysfs_device* dev = NULL;
    if (!drv)
    {
        errno = EINVAL;
        return NULL;
    }
    linklist = read_dir_links(drv->path);
    if (linklist)
    {
        dlist_for_each_data(linklist, ln, char)
        {
            if (!strncmp(ln, SYSFS_MODULE_NAME, strlen(ln)))
                continue;
            dev = sysfs_open_device(drv->bus, ln);
            if (!dev)
            {
                dprintf("Error opening driver's device\n");
                sysfs_close_list(linklist);
                return NULL;
            }
            if (!drv->devices)
            {
                drv->devices = dlist_new_with_delete(
                    sizeof(struct sysfs_device), sysfs_close_driver_device);
                if (!drv->devices)
                {
                    dprintf("Error creating device list\n");
                    sysfs_close_list(linklist);
                    return NULL;
                }
            }
            dlist_unshift_sorted(drv->devices, dev, sort_list);
        }
        sysfs_close_list(linklist);
    }
    return drv->devices;
}
struct dlist * sysfs_get_driver_devices ( struct sysfs_driver * drv ) { char * ln = NULL ; struct dlist * linklist = NULL ; struct sysfs_device * dev = NULL ; if ( ! drv ) { errno = EINVAL ; return NULL ; } linklist = read_dir_links ( drv -> path ) ; if ( linklist ) { dlist_for_each_data ( linklist , ln , char ) { if ( ! strncmp ( ln , SYSFS_MODULE_NAME , strlen ( ln ) ) ) continue ; dev = sysfs_open_device ( drv -> bus , ln ) ; if ( ! dev ) { dprintf ( " \n " ) ; sysfs_close_list ( linklist ) ; return NULL ; } if ( ! drv -> devices ) { drv -> devices = dlist_new_with_delete ( sizeof ( struct sysfs_device ) , sysfs_close_driver_device ) ; if ( ! drv -> devices ) { dprintf ( " \n " ) ; sysfs_close_list ( linklist ) ; return NULL ; } } dlist_unshift_sorted ( drv -> devices , dev , sort_list ) ; } sysfs_close_list ( linklist ) ; } return drv -> devices ; }
sysfs_get_driver_devices: gets list of devices that use the driver
 @drv: sysfs_driver whose device list is needed
 Returns dlist of struct sysfs_device on success and NULL on failure
sysfs_get_driver_devices : gets list of devices that use the driver @drv : sysfs_driver whose device list is needed Returns dlist of struct sysfs_device on success and NULL on failure