cregit-Linux how code gets into the kernel

Release 4.7 drivers/leds/led-triggers.c

Directory: drivers/leds
/*
 * LED Triggers Core
 *
 * Copyright 2005-2007 Openedhand Ltd.
 *
 * Author: Richard Purdie <rpurdie@openedhand.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/spinlock.h>
#include <linux/device.h>
#include <linux/timer.h>
#include <linux/rwsem.h>
#include <linux/leds.h>
#include <linux/slab.h>
#include "leds.h"

/*
 * Nests outside led_cdev->trigger_lock
 */
static DECLARE_RWSEM(triggers_list_lock);

LIST_HEAD(trigger_list);

 /* Used by LED Class */


ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct led_classdev *led_cdev = dev_get_drvdata(dev); struct led_trigger *trig; int ret = count; mutex_lock(&led_cdev->led_access); if (led_sysfs_is_disabled(led_cdev)) { ret = -EBUSY; goto unlock; } if (sysfs_streq(buf, "none")) { led_trigger_remove(led_cdev); goto unlock; } down_read(&triggers_list_lock); list_for_each_entry(trig, &trigger_list, next_trig) { if (sysfs_streq(buf, trig->name)) { down_write(&led_cdev->trigger_lock); led_trigger_set(led_cdev, trig); up_write(&led_cdev->trigger_lock); up_read(&triggers_list_lock); goto unlock; } } up_read(&triggers_list_lock); unlock: mutex_unlock(&led_cdev->led_access); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
richard purdierichard purdie11568.86%350.00%
jacek anaszewskijacek anaszewski4728.14%116.67%
heiner kallweitheiner kallweit42.40%116.67%
marton nemethmarton nemeth10.60%116.67%
Total167100.00%6100.00%

EXPORT_SYMBOL_GPL(led_trigger_store);
ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr, char *buf) { struct led_classdev *led_cdev = dev_get_drvdata(dev); struct led_trigger *trig; int len = 0; down_read(&triggers_list_lock); down_read(&led_cdev->trigger_lock); if (!led_cdev->trigger) len += sprintf(buf+len, "[none] "); else len += sprintf(buf+len, "none "); list_for_each_entry(trig, &trigger_list, next_trig) { if (led_cdev->trigger && !strcmp(led_cdev->trigger->name, trig->name)) len += sprintf(buf+len, "[%s] ", trig->name); else len += sprintf(buf+len, "%s ", trig->name); } up_read(&led_cdev->trigger_lock); up_read(&triggers_list_lock); len += sprintf(len+buf, "\n"); return len; }

Contributors

PersonTokensPropCommitsCommitProp
richard purdierichard purdie172100.00%3100.00%
Total172100.00%3100.00%

EXPORT_SYMBOL_GPL(led_trigger_show); /* Caller must ensure led_cdev->trigger_lock held */
void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig) { unsigned long flags; char *event = NULL; char *envp[2]; const char *name; name = trig ? trig->name : "none"; event = kasprintf(GFP_KERNEL, "TRIGGER=%s", name); /* Remove any existing trigger */ if (led_cdev->trigger) { write_lock_irqsave(&led_cdev->trigger->leddev_list_lock, flags); list_del(&led_cdev->trig_list); write_unlock_irqrestore(&led_cdev->trigger->leddev_list_lock, flags); cancel_work_sync(&led_cdev->set_brightness_work); led_stop_software_blink(led_cdev); if (led_cdev->trigger->deactivate) led_cdev->trigger->deactivate(led_cdev); led_cdev->trigger = NULL; led_set_brightness(led_cdev, LED_OFF); } if (trig) { write_lock_irqsave(&trig->leddev_list_lock, flags); list_add_tail(&led_cdev->trig_list, &trig->led_cdevs); write_unlock_irqrestore(&trig->leddev_list_lock, flags); led_cdev->trigger = trig; if (trig->activate) trig->activate(led_cdev); } if (event) { envp[0] = event; envp[1] = NULL; kobject_uevent_env(&led_cdev->dev->kobj, KOBJ_CHANGE, envp); kfree(event); } }

Contributors

PersonTokensPropCommitsCommitProp
richard purdierichard purdie12251.05%114.29%
colin crosscolin cross7832.64%114.29%
fabio baltierifabio baltieri135.44%114.29%
dmitry eremin-baryshkovdmitry eremin-baryshkov114.60%114.29%
bryan wubryan wu83.35%114.29%
paul collinspaul collins62.51%114.29%
shuah khanshuah khan10.42%114.29%
Total239100.00%7100.00%

EXPORT_SYMBOL_GPL(led_trigger_set);
void led_trigger_remove(struct led_classdev *led_cdev) { down_write(&led_cdev->trigger_lock); led_trigger_set(led_cdev, NULL); up_write(&led_cdev->trigger_lock); }

Contributors

PersonTokensPropCommitsCommitProp
marton nemethmarton nemeth33100.00%1100.00%
Total33100.00%1100.00%

EXPORT_SYMBOL_GPL(led_trigger_remove);
void led_trigger_set_default(struct led_classdev *led_cdev) { struct led_trigger *trig; if (!led_cdev->default_trigger) return; down_read(&triggers_list_lock); down_write(&led_cdev->trigger_lock); list_for_each_entry(trig, &trigger_list, next_trig) { if (!strcmp(led_cdev->default_trigger, trig->name)) led_trigger_set(led_cdev, trig); } up_write(&led_cdev->trigger_lock); up_read(&triggers_list_lock); }

Contributors

PersonTokensPropCommitsCommitProp
richard purdierichard purdie82100.00%2100.00%
Total82100.00%2100.00%

EXPORT_SYMBOL_GPL(led_trigger_set_default);
void led_trigger_rename_static(const char *name, struct led_trigger *trig) { /* new name must be on a temporary string to prevent races */ BUG_ON(name == trig->name); down_write(&triggers_list_lock); /* this assumes that trig->name was originaly allocated to * non constant storage */ strcpy((char *)trig->name, name); up_write(&triggers_list_lock); }

Contributors

PersonTokensPropCommitsCommitProp
fabio baltierifabio baltieri51100.00%1100.00%
Total51100.00%1100.00%

EXPORT_SYMBOL_GPL(led_trigger_rename_static); /* LED Trigger Interface */
int led_trigger_register(struct led_trigger *trig) { struct led_classdev *led_cdev; struct led_trigger *_trig; rwlock_init(&trig->leddev_list_lock); INIT_LIST_HEAD(&trig->led_cdevs); down_write(&triggers_list_lock); /* Make sure the trigger's name isn't already in use */ list_for_each_entry(_trig, &trigger_list, next_trig) { if (!strcmp(_trig->name, trig->name)) { up_write(&triggers_list_lock); return -EEXIST; } } /* Add to the list of led triggers */ list_add_tail(&trig->next_trig, &trigger_list); up_write(&triggers_list_lock); /* Register with any LEDs that have this as a default trigger */ down_read(&leds_list_lock); list_for_each_entry(led_cdev, &leds_list, node) { down_write(&led_cdev->trigger_lock); if (!led_cdev->trigger && led_cdev->default_trigger && !strcmp(led_cdev->default_trigger, trig->name)) led_trigger_set(led_cdev, trig); up_write(&led_cdev->trigger_lock); } up_read(&leds_list_lock); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
richard purdierichard purdie12071.01%360.00%
adam nielsenadam nielsen3923.08%120.00%
bryan wubryan wu105.92%120.00%
Total169100.00%5100.00%

EXPORT_SYMBOL_GPL(led_trigger_register);
void led_trigger_unregister(struct led_trigger *trig) { struct led_classdev *led_cdev; if (list_empty_careful(&trig->next_trig)) return; /* Remove from the list of led triggers */ down_write(&triggers_list_lock); list_del_init(&trig->next_trig); up_write(&triggers_list_lock); /* Remove anyone actively using this trigger */ down_read(&leds_list_lock); list_for_each_entry(led_cdev, &leds_list, node) { down_write(&led_cdev->trigger_lock); if (led_cdev->trigger == trig) led_trigger_set(led_cdev, NULL); up_write(&led_cdev->trigger_lock); } up_read(&leds_list_lock); }

Contributors

PersonTokensPropCommitsCommitProp
richard purdierichard purdie8685.15%360.00%
sasha levinsasha levin1211.88%120.00%
bryan wubryan wu32.97%120.00%
Total101100.00%5100.00%

EXPORT_SYMBOL_GPL(led_trigger_unregister);
static void devm_led_trigger_release(struct device *dev, void *res) { led_trigger_unregister(*(struct led_trigger **)res); }

Contributors

PersonTokensPropCommitsCommitProp
heiner kallweitheiner kallweit27100.00%1100.00%
Total27100.00%1100.00%


int devm_led_trigger_register(struct device *dev, struct led_trigger *trig) { struct led_trigger **dr; int rc; dr = devres_alloc(devm_led_trigger_release, sizeof(*dr), GFP_KERNEL); if (!dr) return -ENOMEM; *dr = trig; rc = led_trigger_register(trig); if (rc) devres_free(dr); else devres_add(dev, dr); return rc; }

Contributors

PersonTokensPropCommitsCommitProp
heiner kallweitheiner kallweit80100.00%1100.00%
Total80100.00%1100.00%

EXPORT_SYMBOL_GPL(devm_led_trigger_register); /* Simple LED Tigger Interface */
void led_trigger_event(struct led_trigger *trig, enum led_brightness brightness) { struct led_classdev *led_cdev; if (!trig) return; read_lock(&trig->leddev_list_lock); list_for_each_entry(led_cdev, &trig->led_cdevs, trig_list) led_set_brightness(led_cdev, brightness); read_unlock(&trig->leddev_list_lock); }

Contributors

PersonTokensPropCommitsCommitProp
marton nemethmarton nemeth2748.21%228.57%
richard purdierichard purdie1832.14%228.57%
zhao gangzhao gang58.93%114.29%
bryan wubryan wu58.93%114.29%
fabio baltierifabio baltieri11.79%114.29%
Total56100.00%7100.00%

EXPORT_SYMBOL_GPL(led_trigger_event);
static void led_trigger_blink_setup(struct led_trigger *trig, unsigned long *delay_on, unsigned long *delay_off, int oneshot, int invert) { struct led_classdev *led_cdev; if (!trig) return; read_lock(&trig->leddev_list_lock); list_for_each_entry(led_cdev, &trig->led_cdevs, trig_list) { if (oneshot) led_blink_set_oneshot(led_cdev, delay_on, delay_off, invert); else led_blink_set(led_cdev, delay_on, delay_off); } read_unlock(&trig->leddev_list_lock); }

Contributors

PersonTokensPropCommitsCommitProp
vasily khoruzhickvasily khoruzhick5460.67%120.00%
fabio baltierifabio baltieri2325.84%120.00%
bryan wubryan wu66.74%240.00%
zhao gangzhao gang66.74%120.00%
Total89100.00%5100.00%


void led_trigger_blink(struct led_trigger *trig, unsigned long *delay_on, unsigned long *delay_off) { led_trigger_blink_setup(trig, delay_on, delay_off, 0, 0); }

Contributors

PersonTokensPropCommitsCommitProp
fabio baltierifabio baltieri33100.00%1100.00%
Total33100.00%1100.00%

EXPORT_SYMBOL_GPL(led_trigger_blink);
void led_trigger_blink_oneshot(struct led_trigger *trig, unsigned long *delay_on, unsigned long *delay_off, int invert) { led_trigger_blink_setup(trig, delay_on, delay_off, 1, invert); }

Contributors

PersonTokensPropCommitsCommitProp
fabio baltierifabio baltieri36100.00%1100.00%
Total36100.00%1100.00%

EXPORT_SYMBOL_GPL(led_trigger_blink_oneshot);
void led_trigger_register_simple(const char *name, struct led_trigger **tp) { struct led_trigger *trig; int err; trig = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); if (trig) { trig->name = name; err = led_trigger_register(trig); if (err < 0) { kfree(trig); trig = NULL; pr_warn("LED trigger %s failed to register (%d)\n", name, err); } } else { pr_warn("LED trigger %s failed to register (no memory)\n", name); } *tp = trig; }

Contributors

PersonTokensPropCommitsCommitProp
marton nemethmarton nemeth6263.92%120.00%
richard purdierichard purdie1212.37%120.00%
masakazu mokunomasakazu mokuno99.28%120.00%
bryan wubryan wu88.25%120.00%
sachin kamatsachin kamat66.19%120.00%
Total97100.00%5100.00%

EXPORT_SYMBOL_GPL(led_trigger_register_simple);
void led_trigger_unregister_simple(struct led_trigger *trig) { if (trig) led_trigger_unregister(trig); kfree(trig); }

Contributors

PersonTokensPropCommitsCommitProp
marton nemethmarton nemeth1770.83%133.33%
bryan wubryan wu416.67%133.33%
richard purdierichard purdie312.50%133.33%
Total24100.00%3100.00%

EXPORT_SYMBOL_GPL(led_trigger_unregister_simple); MODULE_AUTHOR("Richard Purdie"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("LED Triggers Core");

Overall Contributors

PersonTokensPropCommitsCommitProp
richard purdierichard purdie80350.57%518.52%
marton nemethmarton nemeth17310.89%27.41%
fabio baltierifabio baltieri16710.52%311.11%
heiner kallweitheiner kallweit1167.30%27.41%
colin crosscolin cross784.91%13.70%
vasily khoruzhickvasily khoruzhick593.72%13.70%
jacek anaszewskijacek anaszewski472.96%13.70%
bryan wubryan wu442.77%27.41%
adam nielsenadam nielsen392.46%13.70%
sasha levinsasha levin120.76%13.70%
dmitry eremin-baryshkovdmitry eremin-baryshkov110.69%13.70%
zhao gangzhao gang110.69%13.70%
masakazu mokunomasakazu mokuno90.57%13.70%
paul collinspaul collins60.38%13.70%
sachin kamatsachin kamat60.38%13.70%
tejun heotejun heo30.19%13.70%
ingo molnaringo molnar30.19%13.70%
shuah khanshuah khan10.06%13.70%
ezequiel garciaezequiel garcia0.00%00.00%
Total1588100.00%27100.00%
Directory: drivers/leds
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}