diff options
author | Greg Kroah-Hartman <gregkh@suse.de> | 2008-11-19 12:58:28 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2009-01-06 16:52:24 -0500 |
commit | e7f2aa345581b5b500b44a4114bdda642938eb2e (patch) | |
tree | 62dc8aca4e6a823ab448a74ab123a35860c14539 | |
parent | e55c95a3be5e202f0fc30126aff172c706b304f8 (diff) |
Staging: comedi: fix checkpatch.pl issues in comedi_bond.c
This fixes a number of the issues found by checkpatch.pl in the
comedi_bond.c file.
Cc: Calin A. Culianu <calin@ajvar.org>
Cc: David Schleef <ds@schleef.org>
Cc: Frank Mori Hess <fmhess@users.sourceforge.net>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/staging/comedi/drivers/comedi_bond.c | 146 |
1 files changed, 80 insertions, 66 deletions
diff --git a/drivers/staging/comedi/drivers/comedi_bond.c b/drivers/staging/comedi/drivers/comedi_bond.c index 3a65f0316fc9..fc803370a040 100644 --- a/drivers/staging/comedi/drivers/comedi_bond.c +++ b/drivers/staging/comedi/drivers/comedi_bond.c | |||
@@ -23,7 +23,8 @@ | |||
23 | */ | 23 | */ |
24 | /* | 24 | /* |
25 | Driver: comedi_bond | 25 | Driver: comedi_bond |
26 | Description: A driver to 'bond' (merge) multiple subdevices from multiple devices together as one. | 26 | Description: A driver to 'bond' (merge) multiple subdevices from multiple |
27 | devices together as one. | ||
27 | Devices: | 28 | Devices: |
28 | Author: ds | 29 | Author: ds |
29 | Updated: Mon, 10 Oct 00:18:25 -0500 | 30 | Updated: Mon, 10 Oct 00:18:25 -0500 |
@@ -102,18 +103,23 @@ MODULE_LICENSE("GPL"); | |||
102 | # define STR(x) STR1(x) | 103 | # define STR(x) STR1(x) |
103 | #endif | 104 | #endif |
104 | 105 | ||
105 | int debug = 0; | 106 | int debug; |
106 | module_param(debug, int, 0644); | 107 | module_param(debug, int, 0644); |
107 | MODULE_PARM_DESC(debug, | 108 | MODULE_PARM_DESC(debug, "If true, print extra cryptic debugging output useful" |
108 | "If true, print extra cryptic debugging output useful only to developers probably."); | 109 | "only to developers."); |
109 | 110 | ||
110 | #define LOG_MSG(x...) printk(KERN_INFO MODULE_NAME": "x) | 111 | #define LOG_MSG(x...) printk(KERN_INFO MODULE_NAME": "x) |
111 | #define DEBUG(x...) do { if(debug) printk(KERN_DEBUG MODULE_NAME": DEBUG: "x); } while(0) | 112 | #define DEBUG(x...) \ |
113 | do { \ | ||
114 | if (debug) \ | ||
115 | printk(KERN_DEBUG MODULE_NAME": DEBUG: "x); \ | ||
116 | } while (0) | ||
112 | #define WARNING(x...) printk(KERN_WARNING MODULE_NAME ": WARNING: "x) | 117 | #define WARNING(x...) printk(KERN_WARNING MODULE_NAME ": WARNING: "x) |
113 | #define ERROR(x...) printk(KERN_ERR MODULE_NAME ": INTERNAL ERROR: "x) | 118 | #define ERROR(x...) printk(KERN_ERR MODULE_NAME ": INTERNAL ERROR: "x) |
114 | MODULE_AUTHOR("Calin A. Culianu"); | 119 | MODULE_AUTHOR("Calin A. Culianu"); |
115 | MODULE_DESCRIPTION(MODULE_NAME | 120 | MODULE_DESCRIPTION(MODULE_NAME "A driver for COMEDI to bond multiple COMEDI " |
116 | ": A driver for COMEDI to bond multiple COMEDI devices together as one. In the words of John Lennon: 'And the world will live as one...'"); | 121 | "devices together as one. In the words of John Lennon: " |
122 | "'And the world will live as one...'"); | ||
117 | 123 | ||
118 | /* | 124 | /* |
119 | * Board descriptions for two imaginary boards. Describing the | 125 | * Board descriptions for two imaginary boards. Describing the |
@@ -127,8 +133,8 @@ typedef struct BondingBoard BondingBoard; | |||
127 | 133 | ||
128 | static const BondingBoard bondingBoards[] = { | 134 | static const BondingBoard bondingBoards[] = { |
129 | { | 135 | { |
130 | name: MODULE_NAME, | 136 | .name = MODULE_NAME, |
131 | }, | 137 | }, |
132 | }; | 138 | }; |
133 | 139 | ||
134 | /* | 140 | /* |
@@ -142,8 +148,9 @@ struct BondedDevice { | |||
142 | unsigned subdev; | 148 | unsigned subdev; |
143 | unsigned subdev_type; | 149 | unsigned subdev_type; |
144 | unsigned nchans; | 150 | unsigned nchans; |
145 | unsigned chanid_offset; /* The offset into our unified linear channel-id's | 151 | unsigned chanid_offset; /* The offset into our unified linear |
146 | of chanid 0 on this subdevice. */ | 152 | channel-id's of chanid 0 on this |
153 | subdevice. */ | ||
147 | }; | 154 | }; |
148 | typedef struct BondedDevice BondedDevice; | 155 | typedef struct BondedDevice BondedDevice; |
149 | 156 | ||
@@ -172,19 +179,20 @@ typedef struct Private Private; | |||
172 | * the board, and also about the kernel module that contains | 179 | * the board, and also about the kernel module that contains |
173 | * the device code. | 180 | * the device code. |
174 | */ | 181 | */ |
175 | static int bonding_attach(comedi_device * dev, comedi_devconfig * it); | 182 | static int bonding_attach(comedi_device *dev, comedi_devconfig *it); |
176 | static int bonding_detach(comedi_device * dev); | 183 | static int bonding_detach(comedi_device *dev); |
177 | /** Build Private array of all devices.. */ | 184 | /** Build Private array of all devices.. */ |
178 | static int doDevConfig(comedi_device * dev, comedi_devconfig * it); | 185 | static int doDevConfig(comedi_device *dev, comedi_devconfig *it); |
179 | static void doDevUnconfig(comedi_device * dev); | 186 | static void doDevUnconfig(comedi_device *dev); |
180 | /* Ugly implementation of realloc that always copies memory around -- I'm lazy, what can I say? I like to do wasteful memcopies.. :) */ | 187 | /* Ugly implementation of realloc that always copies memory around -- I'm lazy, |
188 | * what can I say? I like to do wasteful memcopies.. :) */ | ||
181 | static void *Realloc(const void *ptr, size_t len, size_t old_len); | 189 | static void *Realloc(const void *ptr, size_t len, size_t old_len); |
182 | 190 | ||
183 | static comedi_driver driver_bonding = { | 191 | static comedi_driver driver_bonding = { |
184 | driver_name:MODULE_NAME, | 192 | .driver_name = MODULE_NAME, |
185 | module:THIS_MODULE, | 193 | .module = THIS_MODULE, |
186 | attach:bonding_attach, | 194 | .attach = bonding_attach, |
187 | detach:bonding_detach, | 195 | .detach = bonding_detach, |
188 | /* It is not necessary to implement the following members if you are | 196 | /* It is not necessary to implement the following members if you are |
189 | * writing a driver for a ISA PnP or PCI card */ | 197 | * writing a driver for a ISA PnP or PCI card */ |
190 | /* Most drivers will support multiple types of boards by | 198 | /* Most drivers will support multiple types of boards by |
@@ -203,15 +211,15 @@ static comedi_driver driver_bonding = { | |||
203 | * the type of board in software. ISA PnP, PCI, and PCMCIA | 211 | * the type of board in software. ISA PnP, PCI, and PCMCIA |
204 | * devices are such boards. | 212 | * devices are such boards. |
205 | */ | 213 | */ |
206 | board_name:&bondingBoards[0].name, | 214 | .board_name = &bondingBoards[0].name, |
207 | offset:sizeof(BondingBoard), | 215 | .offset = sizeof(BondingBoard), |
208 | num_names:sizeof(bondingBoards) / sizeof(BondingBoard), | 216 | .num_names = sizeof(bondingBoards) / sizeof(BondingBoard), |
209 | }; | 217 | }; |
210 | 218 | ||
211 | static int bonding_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, | 219 | static int bonding_dio_insn_bits(comedi_device *dev, comedi_subdevice *s, |
212 | comedi_insn * insn, lsampl_t * data); | 220 | comedi_insn *insn, lsampl_t *data); |
213 | static int bonding_dio_insn_config(comedi_device * dev, comedi_subdevice * s, | 221 | static int bonding_dio_insn_config(comedi_device *dev, comedi_subdevice *s, |
214 | comedi_insn * insn, lsampl_t * data); | 222 | comedi_insn *insn, lsampl_t *data); |
215 | 223 | ||
216 | /* | 224 | /* |
217 | * Attach is called by the Comedi core to configure the driver | 225 | * Attach is called by the Comedi core to configure the driver |
@@ -219,35 +227,35 @@ static int bonding_dio_insn_config(comedi_device * dev, comedi_subdevice * s, | |||
219 | * in the driver structure, dev->board_ptr contains that | 227 | * in the driver structure, dev->board_ptr contains that |
220 | * address. | 228 | * address. |
221 | */ | 229 | */ |
222 | static int bonding_attach(comedi_device * dev, comedi_devconfig * it) | 230 | static int bonding_attach(comedi_device *dev, comedi_devconfig *it) |
223 | { | 231 | { |
224 | comedi_subdevice *s; | 232 | comedi_subdevice *s; |
225 | 233 | ||
226 | LOG_MSG("comedi%d\n", dev->minor); | 234 | LOG_MSG("comedi%d\n", dev->minor); |
227 | 235 | ||
228 | /* | 236 | /* |
229 | * Allocate the private structure area. alloc_private() is a | 237 | * Allocate the private structure area. alloc_private() is a |
230 | * convenient macro defined in comedidev.h. | 238 | * convenient macro defined in comedidev.h. |
231 | */ | 239 | */ |
232 | if (alloc_private(dev, sizeof(Private)) < 0) | 240 | if (alloc_private(dev, sizeof(Private)) < 0) |
233 | return -ENOMEM; | 241 | return -ENOMEM; |
234 | 242 | ||
235 | /* | 243 | /* |
236 | * Setup our bonding from config params.. sets up our Private struct.. | 244 | * Setup our bonding from config params.. sets up our Private struct.. |
237 | */ | 245 | */ |
238 | if (!doDevConfig(dev, it)) | 246 | if (!doDevConfig(dev, it)) |
239 | return -EINVAL; | 247 | return -EINVAL; |
240 | 248 | ||
241 | /* | 249 | /* |
242 | * Initialize dev->board_name. Note that we can use the "thisboard" | 250 | * Initialize dev->board_name. Note that we can use the "thisboard" |
243 | * macro now, since we just initialized it in the last line. | 251 | * macro now, since we just initialized it in the last line. |
244 | */ | 252 | */ |
245 | dev->board_name = devpriv->name; | 253 | dev->board_name = devpriv->name; |
246 | 254 | ||
247 | /* | 255 | /* |
248 | * Allocate the subdevice structures. alloc_subdevice() is a | 256 | * Allocate the subdevice structures. alloc_subdevice() is a |
249 | * convenient macro defined in comedidev.h. | 257 | * convenient macro defined in comedidev.h. |
250 | */ | 258 | */ |
251 | if (alloc_subdevices(dev, 1) < 0) | 259 | if (alloc_subdevices(dev, 1) < 0) |
252 | return -ENOMEM; | 260 | return -ENOMEM; |
253 | 261 | ||
@@ -260,7 +268,10 @@ static int bonding_attach(comedi_device * dev, comedi_devconfig * it) | |||
260 | s->insn_bits = bonding_dio_insn_bits; | 268 | s->insn_bits = bonding_dio_insn_bits; |
261 | s->insn_config = bonding_dio_insn_config; | 269 | s->insn_config = bonding_dio_insn_config; |
262 | 270 | ||
263 | LOG_MSG("attached with %u DIO channels coming from %u different subdevices all bonded together. John Lennon would be proud!\n", devpriv->nchans, devpriv->ndevs); | 271 | LOG_MSG("attached with %u DIO channels coming from %u different " |
272 | "subdevices all bonded together. " | ||
273 | "John Lennon would be proud!\n", | ||
274 | devpriv->nchans, devpriv->ndevs); | ||
264 | 275 | ||
265 | return 1; | 276 | return 1; |
266 | } | 277 | } |
@@ -273,7 +284,7 @@ static int bonding_attach(comedi_device * dev, comedi_devconfig * it) | |||
273 | * allocated by _attach(). dev->private and dev->subdevices are | 284 | * allocated by _attach(). dev->private and dev->subdevices are |
274 | * deallocated automatically by the core. | 285 | * deallocated automatically by the core. |
275 | */ | 286 | */ |
276 | static int bonding_detach(comedi_device * dev) | 287 | static int bonding_detach(comedi_device *dev) |
277 | { | 288 | { |
278 | LOG_MSG("comedi%d: remove\n", dev->minor); | 289 | LOG_MSG("comedi%d: remove\n", dev->minor); |
279 | doDevUnconfig(dev); | 290 | doDevUnconfig(dev); |
@@ -285,8 +296,8 @@ static int bonding_detach(comedi_device * dev) | |||
285 | * useful to applications if you implement the insn_bits interface. | 296 | * useful to applications if you implement the insn_bits interface. |
286 | * This allows packed reading/writing of the DIO channels. The | 297 | * This allows packed reading/writing of the DIO channels. The |
287 | * comedi core can convert between insn_bits and insn_read/write */ | 298 | * comedi core can convert between insn_bits and insn_read/write */ |
288 | static int bonding_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, | 299 | static int bonding_dio_insn_bits(comedi_device *dev, comedi_subdevice *s, |
289 | comedi_insn * insn, lsampl_t * data) | 300 | comedi_insn *insn, lsampl_t *data) |
290 | { | 301 | { |
291 | #define LSAMPL_BITS (sizeof(lsampl_t)*8) | 302 | #define LSAMPL_BITS (sizeof(lsampl_t)*8) |
292 | unsigned nchans = LSAMPL_BITS, num_done = 0, i; | 303 | unsigned nchans = LSAMPL_BITS, num_done = 0, i; |
@@ -303,8 +314,8 @@ static int bonding_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, | |||
303 | /* Grab the channel mask and data of only the bits corresponding | 314 | /* Grab the channel mask and data of only the bits corresponding |
304 | to this subdevice.. need to shift them to zero position of | 315 | to this subdevice.. need to shift them to zero position of |
305 | course. */ | 316 | course. */ |
306 | lsampl_t subdevMask = ((1 << bdev->nchans) - 1); /* Bits corresponding | 317 | /* Bits corresponding to this subdev. */ |
307 | to this subdev. */ | 318 | lsampl_t subdevMask = ((1 << bdev->nchans) - 1); |
308 | lsampl_t writeMask, dataBits; | 319 | lsampl_t writeMask, dataBits; |
309 | 320 | ||
310 | /* Argh, we have >= LSAMPL_BITS chans.. take all bits */ | 321 | /* Argh, we have >= LSAMPL_BITS chans.. take all bits */ |
@@ -332,8 +343,8 @@ static int bonding_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, | |||
332 | return insn->n; | 343 | return insn->n; |
333 | } | 344 | } |
334 | 345 | ||
335 | static int bonding_dio_insn_config(comedi_device * dev, comedi_subdevice * s, | 346 | static int bonding_dio_insn_config(comedi_device *dev, comedi_subdevice *s, |
336 | comedi_insn * insn, lsampl_t * data) | 347 | comedi_insn *insn, lsampl_t *data) |
337 | { | 348 | { |
338 | int chan = CR_CHAN(insn->chanspec), ret, io_bits = s->io_bits; | 349 | int chan = CR_CHAN(insn->chanspec), ret, io_bits = s->io_bits; |
339 | unsigned int io; | 350 | unsigned int io; |
@@ -365,7 +376,8 @@ static int bonding_dio_insn_config(comedi_device * dev, comedi_subdevice * s, | |||
365 | return -EINVAL; | 376 | return -EINVAL; |
366 | break; | 377 | break; |
367 | } | 378 | } |
368 | chan -= bdev->chanid_offset; /* 'real' channel id for this subdev.. */ | 379 | /* 'real' channel id for this subdev.. */ |
380 | chan -= bdev->chanid_offset; | ||
369 | ret = comedi_dio_config(bdev->dev, bdev->subdev, chan, io); | 381 | ret = comedi_dio_config(bdev->dev, bdev->subdev, chan, io); |
370 | if (ret != 1) | 382 | if (ret != 1) |
371 | return -EINVAL; | 383 | return -EINVAL; |
@@ -377,16 +389,15 @@ static int bonding_dio_insn_config(comedi_device * dev, comedi_subdevice * s, | |||
377 | 389 | ||
378 | static void *Realloc(const void *oldmem, size_t newlen, size_t oldlen) | 390 | static void *Realloc(const void *oldmem, size_t newlen, size_t oldlen) |
379 | { | 391 | { |
380 | #define MIN(a,b) (a < b ? a : b) | ||
381 | void *newmem = kmalloc(newlen, GFP_KERNEL); | 392 | void *newmem = kmalloc(newlen, GFP_KERNEL); |
393 | |||
382 | if (newmem && oldmem) | 394 | if (newmem && oldmem) |
383 | memcpy(newmem, oldmem, MIN(oldlen, newlen)); | 395 | memcpy(newmem, oldmem, min(oldlen, newlen)); |
384 | if (oldmem) | 396 | kfree(oldmem); |
385 | kfree(oldmem); | ||
386 | return newmem; | 397 | return newmem; |
387 | } | 398 | } |
388 | 399 | ||
389 | static int doDevConfig(comedi_device * dev, comedi_devconfig * it) | 400 | static int doDevConfig(comedi_device *dev, comedi_devconfig *it) |
390 | { | 401 | { |
391 | int i; | 402 | int i; |
392 | comedi_t *devs_opened[COMEDI_NUM_BOARD_MINORS]; | 403 | comedi_t *devs_opened[COMEDI_NUM_BOARD_MINORS]; |
@@ -428,8 +439,11 @@ static int doDevConfig(comedi_device * dev, comedi_devconfig * it) | |||
428 | /* Do DIO, as that's all we support now.. */ | 439 | /* Do DIO, as that's all we support now.. */ |
429 | while ((sdev = comedi_find_subdevice_by_type(d, COMEDI_SUBD_DIO, | 440 | while ((sdev = comedi_find_subdevice_by_type(d, COMEDI_SUBD_DIO, |
430 | sdev + 1)) > -1) { | 441 | sdev + 1)) > -1) { |
431 | if ((nchans = comedi_get_n_channels(d, sdev)) <= 0) { | 442 | nchans = comedi_get_n_channels(d, sdev); |
432 | ERROR("comedi_get_n_channels() returned %d on minor %u subdev %d!\n", nchans, minor, sdev); | 443 | if (nchans <= 0) { |
444 | ERROR("comedi_get_n_channels() returned %d " | ||
445 | "on minor %u subdev %d!\n", | ||
446 | nchans, minor, sdev); | ||
433 | return 0; | 447 | return 0; |
434 | } | 448 | } |
435 | bdev = kmalloc(sizeof(*bdev), GFP_KERNEL); | 449 | bdev = kmalloc(sizeof(*bdev), GFP_KERNEL); |
@@ -448,7 +462,8 @@ static int doDevConfig(comedi_device * dev, comedi_devconfig * it) | |||
448 | while (nchans--) | 462 | while (nchans--) |
449 | devpriv->chanIdDevMap[devpriv->nchans++] = bdev; | 463 | devpriv->chanIdDevMap[devpriv->nchans++] = bdev; |
450 | 464 | ||
451 | /* Now put bdev pointer at end of devpriv->devs array list.. */ | 465 | /* Now put bdev pointer at end of devpriv->devs array |
466 | * list.. */ | ||
452 | 467 | ||
453 | /* ergh.. ugly.. we need to realloc :( */ | 468 | /* ergh.. ugly.. we need to realloc :( */ |
454 | tmp = devpriv->ndevs * sizeof(bdev); | 469 | tmp = devpriv->ndevs * sizeof(bdev); |
@@ -456,7 +471,8 @@ static int doDevConfig(comedi_device * dev, comedi_devconfig * it) | |||
456 | Realloc(devpriv->devs, | 471 | Realloc(devpriv->devs, |
457 | ++devpriv->ndevs * sizeof(bdev), tmp); | 472 | ++devpriv->ndevs * sizeof(bdev), tmp); |
458 | if (!devpriv->devs) { | 473 | if (!devpriv->devs) { |
459 | ERROR("Could not allocate memory. Out of memory?"); | 474 | ERROR("Could not allocate memory. " |
475 | "Out of memory?"); | ||
460 | return 0; | 476 | return 0; |
461 | } | 477 | } |
462 | 478 | ||
@@ -484,7 +500,7 @@ static int doDevConfig(comedi_device * dev, comedi_devconfig * it) | |||
484 | return 1; | 500 | return 1; |
485 | } | 501 | } |
486 | 502 | ||
487 | static void doDevUnconfig(comedi_device * dev) | 503 | static void doDevUnconfig(comedi_device *dev) |
488 | { | 504 | { |
489 | unsigned long devs_closed = 0; | 505 | unsigned long devs_closed = 0; |
490 | 506 | ||
@@ -499,10 +515,8 @@ static void doDevUnconfig(comedi_device * dev) | |||
499 | } | 515 | } |
500 | kfree(bdev); | 516 | kfree(bdev); |
501 | } | 517 | } |
502 | if (devpriv->devs) { | 518 | kfree(devpriv->devs); |
503 | kfree(devpriv->devs); | 519 | devpriv->devs = 0; |
504 | devpriv->devs = 0; | ||
505 | } | ||
506 | kfree(devpriv); | 520 | kfree(devpriv); |
507 | dev->private = 0; | 521 | dev->private = 0; |
508 | } | 522 | } |