[PATCH 08/17] staging: comedi: ni_65xx: remove the need for the subdevice private data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There is only one member in the subdevice private data, an unsigned value
that is the 'base_port' that the subdevice uses to access the port registers.

Just cast the appropriate value into s->private instead of allocating the
private data for each subdevice. The casts are a bit of a nusance but it
removes the unnecessary allocations.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregk@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/drivers/ni_65xx.c | 39 ++++++++++++--------------------
 1 file changed, 14 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c
index 8c0f5d3..74af6c7 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -262,25 +262,16 @@ struct ni_65xx_private {
 	void __iomem *mmio;
 };
 
-struct ni_65xx_subdevice_private {
-	unsigned base_port;
-};
-
-static inline struct ni_65xx_subdevice_private *sprivate(struct comedi_subdevice
-							 *subdev)
-{
-	return subdev->private;
-}
-
 static int ni_65xx_dio_insn_config(struct comedi_device *dev,
 				   struct comedi_subdevice *s,
 				   struct comedi_insn *insn,
 				   unsigned int *data)
 {
 	struct ni_65xx_private *devpriv = dev->private;
+	unsigned long base_port = (unsigned long)s->private;
 	unsigned int chan = CR_CHAN(insn->chanspec);
 	unsigned int chan_mask = 1 << (chan % ni_65xx_channels_per_port);
-	unsigned port = sprivate(s)->base_port + ni_65xx_port_by_channel(chan);
+	unsigned port = base_port + ni_65xx_port_by_channel(chan);
 	unsigned int interval;
 	unsigned int val;
 
@@ -345,6 +336,7 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
 				 struct comedi_insn *insn, unsigned int *data)
 {
 	struct ni_65xx_private *devpriv = dev->private;
+	unsigned long base_port = (unsigned long)s->private;
 	int base_bitfield_channel;
 	unsigned read_bits = 0;
 	int last_port_offset = ni_65xx_port_by_channel(s->n_chan - 1);
@@ -353,7 +345,7 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
 	base_bitfield_channel = CR_CHAN(insn->chanspec);
 	for (port_offset = ni_65xx_port_by_channel(base_bitfield_channel);
 	     port_offset <= last_port_offset; port_offset++) {
-		unsigned port = sprivate(s)->base_port + port_offset;
+		unsigned port = base_port + port_offset;
 		int base_port_channel = port_offset * ni_65xx_channels_per_port;
 		unsigned port_mask, port_data, bits;
 		int bitshift = base_port_channel - base_bitfield_channel;
@@ -543,7 +535,6 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
 	struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 	const struct ni_65xx_board *board = NULL;
 	struct ni_65xx_private *devpriv;
-	struct ni_65xx_subdevice_private *spriv;
 	struct comedi_subdevice *s;
 	unsigned i;
 	int ret;
@@ -589,10 +580,9 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
 		s->maxdata = 1;
 		s->insn_config = ni_65xx_dio_insn_config;
 		s->insn_bits = ni_65xx_dio_insn_bits;
-		spriv = comedi_alloc_spriv(s, sizeof(*spriv));
-		if (!spriv)
-			return -ENOMEM;
-		spriv->base_port = 0;
+
+		/* the input ports always start at port 0 */
+		s->private = (void *)0;
 	} else {
 		s->type = COMEDI_SUBD_UNUSED;
 	}
@@ -606,10 +596,9 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
 		s->range_table = &range_digital;
 		s->maxdata = 1;
 		s->insn_bits = ni_65xx_dio_insn_bits;
-		spriv = comedi_alloc_spriv(s, sizeof(*spriv));
-		if (!spriv)
-			return -ENOMEM;
-		spriv->base_port = board->num_di_ports;
+
+		/* the output ports always start after the input ports */
+		s->private = (void *)(unsigned long)board->num_di_ports;
 	} else {
 		s->type = COMEDI_SUBD_UNUSED;
 	}
@@ -624,10 +613,10 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
 		s->maxdata = 1;
 		s->insn_config = ni_65xx_dio_insn_config;
 		s->insn_bits = ni_65xx_dio_insn_bits;
-		spriv = comedi_alloc_spriv(s, sizeof(*spriv));
-		if (!spriv)
-			return -ENOMEM;
-		spriv->base_port = 0;
+
+		/* the input/output ports always start at port 0 */
+		s->private = (void *)0;
+
 		/* configure all ports for input */
 		for (i = 0; i < board->num_dio_ports; ++i) {
 			writeb(NI_65XX_IO_SEL_INPUT,
-- 
1.9.3

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux