aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/mon/mon_bin.c
diff options
context:
space:
mode:
authorPete Zaitcev <zaitcev@redhat.com>2007-05-03 19:51:16 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-07-12 19:29:47 -0400
commitce7cd137fced114d49178b73d468b82096a107fb (patch)
treedfc1f49df82d6ec3b301d786e79ae9481dcc83dd /drivers/usb/mon/mon_bin.c
parent49cdee0ed0fce9e1bda81f5dcad8d5cce6aec983 (diff)
usbmon: Add class for binary interface
Add a class which allows for an easier integration with udev. This code was originally written by Paolo Abeni, and arrived to my tree as a part of big patch to add binary API on December 18. As I understand, Paolo always meant the class to be a part of the whole thing. This is his udev rule to go along with the patch: KERNEL=="usbmon[0-9]*", NAME="usbmon%n", MODE="0440",OWNER="root",GROUP="bin" Signed-off-by: Pete Zaitcev <zaitcev@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/mon/mon_bin.c')
-rw-r--r--drivers/usb/mon/mon_bin.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index 0af11a66207c..c03dfd7a9d36 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -4,7 +4,7 @@
4 * This is a binary format reader. 4 * This is a binary format reader.
5 * 5 *
6 * Copyright (C) 2006 Paolo Abeni (paolo.abeni@email.it) 6 * Copyright (C) 2006 Paolo Abeni (paolo.abeni@email.it)
7 * Copyright (C) 2006 Pete Zaitcev (zaitcev@redhat.com) 7 * Copyright (C) 2006,2007 Pete Zaitcev (zaitcev@redhat.com)
8 */ 8 */
9 9
10#include <linux/kernel.h> 10#include <linux/kernel.h>
@@ -172,6 +172,7 @@ static inline struct mon_bin_hdr *MON_OFF2HDR(const struct mon_reader_bin *rp,
172 172
173#define MON_RING_EMPTY(rp) ((rp)->b_cnt == 0) 173#define MON_RING_EMPTY(rp) ((rp)->b_cnt == 0)
174 174
175static struct class *mon_bin_class;
175static dev_t mon_bin_dev0; 176static dev_t mon_bin_dev0;
176static struct cdev mon_bin_cdev; 177static struct cdev mon_bin_cdev;
177 178
@@ -1144,10 +1145,38 @@ static void mon_free_buff(struct mon_pgmap *map, int npages)
1144 free_page((unsigned long) map[n].ptr); 1145 free_page((unsigned long) map[n].ptr);
1145} 1146}
1146 1147
1148int mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus)
1149{
1150 struct device *dev;
1151 unsigned minor = ubus? ubus->busnum: 0;
1152
1153 if (minor >= MON_BIN_MAX_MINOR)
1154 return 0;
1155
1156 dev = device_create(mon_bin_class, ubus? ubus->controller: NULL,
1157 MKDEV(MAJOR(mon_bin_dev0), minor), "usbmon%d", minor);
1158 if (IS_ERR(dev))
1159 return 0;
1160
1161 mbus->classdev = dev;
1162 return 1;
1163}
1164
1165void mon_bin_del(struct mon_bus *mbus)
1166{
1167 device_destroy(mon_bin_class, mbus->classdev->devt);
1168}
1169
1147int __init mon_bin_init(void) 1170int __init mon_bin_init(void)
1148{ 1171{
1149 int rc; 1172 int rc;
1150 1173
1174 mon_bin_class = class_create(THIS_MODULE, "usbmon");
1175 if (IS_ERR(mon_bin_class)) {
1176 rc = PTR_ERR(mon_bin_class);
1177 goto err_class;
1178 }
1179
1151 rc = alloc_chrdev_region(&mon_bin_dev0, 0, MON_BIN_MAX_MINOR, "usbmon"); 1180 rc = alloc_chrdev_region(&mon_bin_dev0, 0, MON_BIN_MAX_MINOR, "usbmon");
1152 if (rc < 0) 1181 if (rc < 0)
1153 goto err_dev; 1182 goto err_dev;
@@ -1164,6 +1193,8 @@ int __init mon_bin_init(void)
1164err_add: 1193err_add:
1165 unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR); 1194 unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR);
1166err_dev: 1195err_dev:
1196 class_destroy(mon_bin_class);
1197err_class:
1167 return rc; 1198 return rc;
1168} 1199}
1169 1200
@@ -1171,4 +1202,5 @@ void mon_bin_exit(void)
1171{ 1202{
1172 cdev_del(&mon_bin_cdev); 1203 cdev_del(&mon_bin_cdev);
1173 unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR); 1204 unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR);
1205 class_destroy(mon_bin_class);
1174} 1206}