/alps/bar_resolve

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/bar_resolve

« back to all changes in this revision

Viewing changes to mod.c

  • Committer: Suren A. Chilingaryan
  • Date: 2016-03-02 19:01:33 UTC
  • Revision ID: csa@suren.me-20160302190133-2suzxss2vze5ao54
Finalyze the sample

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
#include <linux/cdev.h>
6
6
#include <linux/fs.h>
7
7
#include <linux/slab.h>
 
8
#include <linux/semaphore.h>
8
9
 
9
10
 
10
11
#include "mod.h"
24
25
 
25
26
 
26
27
static dev_t test_devno;                        /**< major number */
27
 
static test_dev_t **test_devs = NULL;   /**< per-device context */
28
 
static spinlock_t test_devs_lock;       /**< lock protecting creation/destruction of devices */
 
28
static test_dev_t **test_devs = NULL;           /**< per-device context */
 
29
static DEFINE_SEMAPHORE(test_devs_mtx);            /**< mutex protecting creation/destruction of devices */
29
30
static struct class *test_class;                /**< device class */
30
31
 
31
32
static void test_module_destroy_cdev(test_dev_t *test)
55
56
    test->cdev.owner = THIS_MODULE;
56
57
    test->cdev.ops = test_get_fops();
57
58
 
58
 
    spin_lock(&test_devs_lock);
 
59
    down(&test_devs_mtx);
59
60
    for (i = 0; i < test_minors; i++) {
60
61
        if (!test_devs[i])
61
62
            break;
84
85
    dev_set_drvdata(test->dev, test);
85
86
 
86
87
    test_devs[i] = test;
87
 
    spin_unlock(&test_devs_lock);
 
88
    up(&test_devs_mtx);
88
89
 
89
90
    err = test_sysfs_init(test);
90
91
    if (err) goto fail_sysfs;
94
95
    return 0;
95
96
 
96
97
fail:
97
 
    spin_unlock(&test_devs_lock);
 
98
    up(&test_devs_mtx);
98
99
fail_sysfs:
99
100
    test_module_destroy_cdev(test);
100
101
    return err;
124
125
{
125
126
    int err;
126
127
 
127
 
    spin_lock_init(&test_devs_lock);
128
 
 
129
128
    if ((err = alloc_chrdev_region(&test_devno, 0, test_minors, TEST_NODE))) {
130
129
        mod_info("Couldn't allocate chrdev region. Module not loaded.\n");
131
130
        goto alloc_chrdev_fail;