cregit-Linux how code gets into the kernel

Release 4.11 drivers/staging/comedi/kcomedilib/kcomedilib_main.c

/*
 * kcomedilib/kcomedilib.c
 * a comedlib interface for kernel modules
 *
 * COMEDI - Linux Control and Measurement Device Interface
 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <linux/module.h>

#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/fcntl.h>
#include <linux/mm.h>
#include <linux/io.h>

#include "../comedi.h"
#include "../comedilib.h"
#include "../comedidev.h"

MODULE_AUTHOR("David Schleef <ds@schleef.org>");
MODULE_DESCRIPTION("Comedi kernel library");
MODULE_LICENSE("GPL");


struct comedi_device *comedi_open(const char *filename) { struct comedi_device *dev, *retval = NULL; unsigned int minor; if (strncmp(filename, "/dev/comedi", 11) != 0) return NULL; if (kstrtouint(filename + 11, 0, &minor)) return NULL; if (minor >= COMEDI_NUM_BOARD_MINORS) return NULL; dev = comedi_dev_get_from_minor(minor); if (!dev) return NULL; down_read(&dev->attach_lock); if (dev->attached) retval = dev; else retval = NULL; up_read(&dev->attach_lock); if (!retval) comedi_dev_put(dev); return retval; }

Contributors

PersonTokensPropCommitsCommitProp
David A. Schleef6954.33%114.29%
Ian Abbott4333.86%228.57%
Chase Southwood107.87%114.29%
H Hartley Sweeten32.36%228.57%
Greg Kroah-Hartman21.57%114.29%
Total127100.00%7100.00%

EXPORT_SYMBOL_GPL(comedi_open);
int comedi_close(struct comedi_device *dev) { comedi_dev_put(dev); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
David A. Schleef1055.56%125.00%
Ian Abbott633.33%250.00%
Greg Kroah-Hartman211.11%125.00%
Total18100.00%4100.00%

EXPORT_SYMBOL_GPL(comedi_close);
static int comedi_do_insn(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { struct comedi_subdevice *s; int ret; mutex_lock(&dev->mutex); if (!dev->attached) { ret = -EINVAL; goto error; } /* a subdevice instruction */ if (insn->subdev >= dev->n_subdevices) { ret = -EINVAL; goto error; } s = &dev->subdevices[insn->subdev]; if (s->type == COMEDI_SUBD_UNUSED) { dev_err(dev->class_dev, "%d not usable subdevice\n", insn->subdev); ret = -EIO; goto error; } /* XXX check lock */ ret = comedi_check_chanlist(s, 1, &insn->chanspec); if (ret < 0) { dev_err(dev->class_dev, "bad chanspec\n"); ret = -EINVAL; goto error; } if (s->busy) { ret = -EBUSY; goto error; } s->busy = dev; switch (insn->insn) { case INSN_BITS: ret = s->insn_bits(dev, s, insn, data); break; case INSN_CONFIG: /* XXX should check instruction length */ ret = s->insn_config(dev, s, insn, data); break; default: ret = -EINVAL; break; } s->busy = NULL; error: mutex_unlock(&dev->mutex); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
David A. Schleef18472.73%17.69%
Ian Abbott3313.04%17.69%
Greg Kroah-Hartman114.35%430.77%
Toshiaki Yamane103.95%17.69%
H Hartley Sweeten83.16%215.38%
Bill Pemberton62.37%323.08%
Gustavo A. R. Silva10.40%17.69%
Total253100.00%13100.00%


int comedi_dio_get_config(struct comedi_device *dev, unsigned int subdev, unsigned int chan, unsigned int *io) { struct comedi_insn insn; unsigned int data[2]; int ret; memset(&insn, 0, sizeof(insn)); insn.insn = INSN_CONFIG; insn.n = 2; insn.subdev = subdev; insn.chanspec = CR_PACK(chan, 0, 0); data[0] = INSN_CONFIG_DIO_QUERY; data[1] = 0; ret = comedi_do_insn(dev, &insn, data); if (ret >= 0) *io = data[1]; return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Ian Abbott124100.00%1100.00%
Total124100.00%1100.00%

EXPORT_SYMBOL_GPL(comedi_dio_get_config);
int comedi_dio_config(struct comedi_device *dev, unsigned int subdev, unsigned int chan, unsigned int io) { struct comedi_insn insn; memset(&insn, 0, sizeof(insn)); insn.insn = INSN_CONFIG; insn.n = 1; insn.subdev = subdev; insn.chanspec = CR_PACK(chan, 0, 0); return comedi_do_insn(dev, &insn, &io); }

Contributors

PersonTokensPropCommitsCommitProp
Greg Kroah-Hartman7996.34%266.67%
H Hartley Sweeten33.66%133.33%
Total82100.00%3100.00%

EXPORT_SYMBOL_GPL(comedi_dio_config);
int comedi_dio_bitfield2(struct comedi_device *dev, unsigned int subdev, unsigned int mask, unsigned int *bits, unsigned int base_channel) { struct comedi_insn insn; unsigned int data[2]; unsigned int n_chan; unsigned int shift; int ret; base_channel = CR_CHAN(base_channel); n_chan = comedi_get_n_channels(dev, subdev); if (base_channel >= n_chan) return -EINVAL; memset(&insn, 0, sizeof(insn)); insn.insn = INSN_BITS; insn.chanspec = base_channel; insn.n = 2; insn.subdev = subdev; data[0] = mask; data[1] = *bits; /* * Most drivers ignore the base channel in insn->chanspec. * Fix this here if the subdevice has <= 32 channels. */ if (n_chan <= 32) { shift = base_channel; if (shift) { insn.chanspec = 0; data[0] <<= shift; data[1] <<= shift; } } else { shift = 0; } ret = comedi_do_insn(dev, &insn, data); *bits = data[1] >> shift; return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Greg Kroah-Hartman10352.02%250.00%
Ian Abbott9346.97%125.00%
H Hartley Sweeten21.01%125.00%
Total198100.00%4100.00%

EXPORT_SYMBOL_GPL(comedi_dio_bitfield2);
int comedi_find_subdevice_by_type(struct comedi_device *dev, int type, unsigned int subd) { struct comedi_subdevice *s; int ret = -ENODEV; down_read(&dev->attach_lock); if (dev->attached) for (; subd < dev->n_subdevices; subd++) { s = &dev->subdevices[subd]; if (s->type == type) { ret = subd; break; } } up_read(&dev->attach_lock); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Greg Kroah-Hartman4953.26%250.00%
Ian Abbott3032.61%125.00%
H Hartley Sweeten1314.13%125.00%
Total92100.00%4100.00%

EXPORT_SYMBOL_GPL(comedi_find_subdevice_by_type);
int comedi_get_n_channels(struct comedi_device *dev, unsigned int subdevice) { int n; down_read(&dev->attach_lock); if (!dev->attached || subdevice >= dev->n_subdevices) n = 0; else n = dev->subdevices[subdevice].n_chan; up_read(&dev->attach_lock); return n; }

Contributors

PersonTokensPropCommitsCommitProp
Ian Abbott4264.62%125.00%
Greg Kroah-Hartman2030.77%250.00%
H Hartley Sweeten34.62%125.00%
Total65100.00%4100.00%

EXPORT_SYMBOL_GPL(comedi_get_n_channels);
static int __init kcomedilib_module_init(void) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Cheah Kok Cheong12100.00%1100.00%
Total12100.00%1100.00%


static void __exit kcomedilib_module_exit(void) { }

Contributors

PersonTokensPropCommitsCommitProp
Cheah Kok Cheong8100.00%1100.00%
Total8100.00%1100.00%

module_init(kcomedilib_module_init); module_exit(kcomedilib_module_exit);

Overall Contributors

PersonTokensPropCommitsCommitProp
Ian Abbott37735.23%416.00%
David A. Schleef30728.69%14.00%
Greg Kroah-Hartman29027.10%728.00%
H Hartley Sweeten383.55%520.00%
Cheah Kok Cheong302.80%14.00%
Toshiaki Yamane100.93%14.00%
Chase Southwood100.93%14.00%
Bill Pemberton60.56%312.00%
Gustavo A. R. Silva10.09%14.00%
Nayeemahmed Badebade10.09%14.00%
Total1070100.00%25100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.