Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0480bcb9 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman
Browse files

staging: comedi: have comedi_set_spriv() allocate the memory



As suggested by Ian Abbott, comedi_set_spriv() can only be used to
set the subdevice->private pointer to something that can be kfree()'d.
Rename the function to comedi_alloc_spriv() and have it kzalloc() the
memory as well as set the private pointer. This saves a function call
in the drivers and avoids the possibility of incorrectly calling
comedi_set_spriv() for some pointer that is not meant to be kfree()'d.

Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2eb226dc
Loading
Loading
Loading
Loading
+8 −6
Original line number Original line Diff line number Diff line
@@ -532,19 +532,21 @@ static bool comedi_is_subdevice_idle(struct comedi_subdevice *s)
}
}


/**
/**
 * comedi_set_spriv() - Set the subdevice private data pointer.
 * comedi_alloc_spriv() - Allocate memory for the subdevice private data.
 * @s: comedi_subdevice struct
 * @s: comedi_subdevice struct
 * @data: pointer to the private data
 * @size: size of the memory to allocate
 *
 *
 * This also sets the subdevice runflags to allow the core to automatically
 * This also sets the subdevice runflags to allow the core to automatically
 * free the private data during the detach.
 * free the private data during the detach.
 */
 */
void comedi_set_spriv(struct comedi_subdevice *s, void *data)
void *comedi_alloc_spriv(struct comedi_subdevice *s, size_t size)
{
{
	s->private = data;
	s->private = kzalloc(size, GFP_KERNEL);
	if (s->private)
		comedi_set_subdevice_runflags(s, ~0, SRF_FREE_SPRIV);
		comedi_set_subdevice_runflags(s, ~0, SRF_FREE_SPRIV);
	return s->private;
}
}
EXPORT_SYMBOL_GPL(comedi_set_spriv);
EXPORT_SYMBOL_GPL(comedi_alloc_spriv);


/*
/*
   This function restores a subdevice to an idle state.
   This function restores a subdevice to an idle state.
+2 −1
Original line number Original line Diff line number Diff line
@@ -270,7 +270,8 @@ enum subdevice_runflags {
};
};


bool comedi_is_subdevice_running(struct comedi_subdevice *s);
bool comedi_is_subdevice_running(struct comedi_subdevice *s);
void comedi_set_spriv(struct comedi_subdevice *s, void *data);

void *comedi_alloc_spriv(struct comedi_subdevice *s, size_t size);


int comedi_check_chanlist(struct comedi_subdevice *s,
int comedi_check_chanlist(struct comedi_subdevice *s,
			  int n,
			  int n,
+1 −3
Original line number Original line Diff line number Diff line
@@ -76,7 +76,6 @@ I/O port base address can be found in the output of 'lspci -v'.
#include "../comedidev.h"
#include "../comedidev.h"


#include <linux/ioport.h>
#include <linux/ioport.h>
#include <linux/slab.h>


#include "comedi_fc.h"
#include "comedi_fc.h"
#include "8255.h"
#include "8255.h"
@@ -285,10 +284,9 @@ int subdev_8255_init(struct comedi_device *dev, struct comedi_subdevice *s,
{
{
	struct subdev_8255_private *spriv;
	struct subdev_8255_private *spriv;


	spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
	spriv = comedi_alloc_spriv(s, sizeof(*spriv));
	if (!spriv)
	if (!spriv)
		return -ENOMEM;
		return -ENOMEM;
	comedi_set_spriv(s, spriv);


	spriv->iobase	= iobase;
	spriv->iobase	= iobase;
	spriv->io	= io ? io : subdev_8255_io;
	spriv->io	= io ? io : subdev_8255_io;
+1 −2
Original line number Original line Diff line number Diff line
@@ -126,10 +126,9 @@ int addi_watchdog_init(struct comedi_subdevice *s, unsigned long iobase)
{
{
	struct addi_watchdog_private *spriv;
	struct addi_watchdog_private *spriv;


	spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
	spriv = comedi_alloc_spriv(s, sizeof(*spriv));
	if (!spriv)
	if (!spriv)
		return -ENOMEM;
		return -ENOMEM;
	comedi_set_spriv(s, spriv);


	spriv->iobase = iobase;
	spriv->iobase = iobase;


+3 −6
Original line number Original line Diff line number Diff line
@@ -556,10 +556,9 @@ dio200_subdev_intr_init(struct comedi_device *dev, struct comedi_subdevice *s,
	const struct dio200_layout *layout = dio200_dev_layout(dev);
	const struct dio200_layout *layout = dio200_dev_layout(dev);
	struct dio200_subdev_intr *subpriv;
	struct dio200_subdev_intr *subpriv;


	subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
	subpriv = comedi_alloc_spriv(s, sizeof(*subpriv));
	if (!subpriv)
	if (!subpriv)
		return -ENOMEM;
		return -ENOMEM;
	comedi_set_spriv(s, subpriv);


	subpriv->ofs = offset;
	subpriv->ofs = offset;
	subpriv->valid_isns = valid_isns;
	subpriv->valid_isns = valid_isns;
@@ -883,10 +882,9 @@ dio200_subdev_8254_init(struct comedi_device *dev, struct comedi_subdevice *s,
	struct dio200_subdev_8254 *subpriv;
	struct dio200_subdev_8254 *subpriv;
	unsigned int chan;
	unsigned int chan;


	subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
	subpriv = comedi_alloc_spriv(s, sizeof(*subpriv));
	if (!subpriv)
	if (!subpriv)
		return -ENOMEM;
		return -ENOMEM;
	comedi_set_spriv(s, subpriv);


	s->type = COMEDI_SUBD_COUNTER;
	s->type = COMEDI_SUBD_COUNTER;
	s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
	s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
@@ -1019,10 +1017,9 @@ static int dio200_subdev_8255_init(struct comedi_device *dev,
{
{
	struct dio200_subdev_8255 *subpriv;
	struct dio200_subdev_8255 *subpriv;


	subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
	subpriv = comedi_alloc_spriv(s, sizeof(*subpriv));
	if (!subpriv)
	if (!subpriv)
		return -ENOMEM;
		return -ENOMEM;
	comedi_set_spriv(s, subpriv);


	subpriv->ofs = offset;
	subpriv->ofs = offset;


Loading