Skip to contentSkip to conversation

Staging: comedi: fix coding style issues in unioxx5.c

PATCH Superseded Conrad Gomes 3 participants 3 messages Nov 1, 2013 – Nov 18, 2013 1 message not in the archive Staging

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: comedi: fix coding style issues in unioxx5.c

This is a patch which fixes coding style issues in unioxx5.c found by checkpatch.pl

1) Replaced printk with pr_info and pr_err
2) Reinitialized n_subd before for loop to fix over 80 character warning
3) Reworded comment to fix 80 character warning

---
 drivers/staging/comedi/drivers/unioxx5.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/staging/comedi/drivers/unioxx5.c +6 -4
index 93eec2f..de68e3a 100644
@@ -96,7 +96,7 @@ static void __unioxx5_digital_config(struct unioxx5_subd_priv *usp, int mode)
 	int i, mask;
 
 	mask = (mode == ALL_2_OUTPUT) ? 0xFF : 0x00;
-	printk("COMEDI: mode = %d\n", mask);
+	pr_info("COMEDI: mode = %d\n", mask);
 
 	outb(1, usp->usp_iobase + 0);
 
@@ -185,7 +185,7 @@ static int __unioxx5_analog_read(struct unioxx5_subd_priv *usp,
 
 	/* if four bytes readding error occurs - return 0(false) */
 	if ((control & Rx4CA_ERR_MASK)) {
-		printk("COMEDI: 4 bytes error\n");
+		pr_err("COMEDI: 4 bytes error\n");
 		return 0;
 	}
 
@@ -436,8 +436,10 @@ static int unioxx5_attach(struct comedi_device *dev,
 	dev->iobase = iobase;
 	iobase += UNIOXX5_SUBDEV_BASE;
 
-	/* defining number of subdevices and getting they types (it must be 'g01')  */
-	for (i = n_subd = 0, ba = iobase; i < 4; i++, ba += UNIOXX5_SUBDEV_ODDS) {
+	n_subd = 0;
+
+	/* getting number of subdevices with types 'g01'*/
+	for (i = 0, ba = iobase; i < 4; i++, ba += UNIOXX5_SUBDEV_ODDS) {
 		id = inb(ba + 0xE);
 		num = inb(ba + 0xF);
 
Signature · 1 line
1.7.9.5
maintainer
#1 lore raw
Quoted 4 lines · Conrad Gomes

This is a patch which fixes coding style issues in unioxx5.c found by checkpatch.pl

1) Replaced printk with pr_info and pr_err

Drivers should never call printk() as they all have access to a struct device somewhere. So please call dev_info() or dev_err() instead.

Quoted 4 lines

2) Reinitialized n_subd before for loop to fix over 80 character warning
3) Reworded comment to fix 80 character warning

Patches should do one thing, not 3 things. Care to break this up into "one logical change per patch"? Yes, it's a small thing, but if you had done this already, I could have taken the other 2 patches and you would have just had to redo one patch in this series...

thanks,

greg k-h

A message that is not in the archive (sent off-list or not yet received): CALxff2GmatgMQF_2yQ9g=tZzh=J-5fKt89sFAU4oYq_FBJHNag@mail.gmail.com

#3 lore raw
Quoted 22 lines · Conrad Gomes

Hi,

No problem, I'll break this up and resend it.

In order to use dev_info type functions I was planning on assigning the comedi device's struct device to the struct subdevice's class_dev as follows in comedi_alloc_subdevices as it appears that is is not used(I could be wrong):

drivers/staging/comedi/drivers.c +1 -0
index 8f02bf6..e4c44ae 100644
@@ -90,6 +90,7 @@ int comedi_alloc_subdevices(struct comedi_device *dev,
 int num_subdevices)
                 s->async_dma_dir = DMA_NONE;
                 spin_lock_init(&s->spin_lock);
                 s->minor = -1;
+               s->class_dev = dev->class_dev;
         }
         return 0;
Quoted 1 line
  }

The class_dev member is assigned by comedi_alloc_subdevice_minor(s) (which will be called if the subdevice supports asynchronous comedi commands) and is kept around for the call to comedi_free_subdevice_minor(s).

The struct comedi_subdevice has a pointer back to the struct comedi_device. The class_dev member in the struct comedi_device can be used as the device pointer parameter of dev_info() etc.

Quoted 19 lines

And adding a reference to the subdevice in the private data structure unioxx5_subd_priv in order to substitute pr_info with dev_info. If this is fine I'll remove all references of pr_info in the file:

drivers/staging/comedi/drivers/unioxx5.c +1 -0
index 2b1ece8..bb8f5a4 100644
@@ -72,6 +72,7 @@ Devices: [Fastwel] UNIOxx-5 (unioxx5),
 
  /* 'private' structure for each subdevice */
  struct unioxx5_subd_priv {
+       struct comedi_subdevice *subdevice;
         int usp_iobase;
         /* 12 modules. each can be 70L or 73L */
         unsigned char usp_module_type[12];
@@ -94,9 +95,10 @@ static int __unioxx5_define_chan_offset(int chan_num)
  static void __unioxx5_digital_config(struct unioxx5_subd_priv *usp,

drivers/staging/comedi/drivers/unioxx5.c static int __unioxx5_define_chan_offset(int chan_num) · line 104

Quoted 10 lines
drivers/staging/comedi/drivers/unioxx5.c +2 -1
 int mode)
  {
         int i, mask;
+       struct device *dev = usp->subdevice->class_dev;
 
         mask = (mode == ALL_2_OUTPUT) ? 0xFF : 0x00;
-       printk("COMEDI: mode = %d\n", mask);
+       dev_info(dev, "COMEDI: mode = %d\n", mask);
 
         outb(1, usp->usp_iobase + 0);

It would be better to change those functions to pass the pointer to the struct comedi_subdevice instead of the pointer to the struct unioxx5_subd_priv.

A variable or parameter named 'dev' in the comedi drivers is usually of type struct comedi_device for consistency.

The message passed to dev_info() wouldn't need the "COMEDI:" prefix - it's redundant.

Also, this particular message should be a dev_dbg() at best, and probably better not to have it at all!

For the sake of example, the above function could start as follows:

static void __unioxx5_digital_config(struct comedi_subdevice *s, int mode)

{
	struct unioxx5_subd_priv *usp = s->private;
	struct device *csdev = s->device->class_dev;
	int i, mask;

	mask = (mode == ALL_2_OUTPUT) ? 0xFF : 0x00;
	dev_dbg(csdev, "mode = %d\n", mask);
Signature · 2 lines
-=( Ian Abbott @ MEV Ltd.    E-mail: <[email protected]>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-