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

Commit 8bdeeb26 authored by Dan Carpenter's avatar Dan Carpenter Committed by Greg Kroah-Hartman
Browse files

Staging: ipack: returning a freed pointer



If ipack_device_register() returns an error, then we returned a freed
pointer.  The caller doesn't use it, but it means we return success to
the user instead of returning an error code.

I kind of rewrote the error handling in this function as a cleanup.

Cc: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent ba4dc61f
Loading
Loading
Loading
Loading
+14 −11
Original line number Original line Diff line number Diff line
@@ -372,7 +372,7 @@ static struct ipack_device *tpci200_slot_register(const char *board_name,
						  unsigned int slot_position)
						  unsigned int slot_position)
{
{
	int found = 0;
	int found = 0;
	struct ipack_device  *dev = NULL;
	struct ipack_device  *dev;
	struct tpci200_board *tpci200;
	struct tpci200_board *tpci200;


	list_for_each_entry(tpci200, &tpci200_list, list) {
	list_for_each_entry(tpci200, &tpci200_list, list) {
@@ -390,16 +390,16 @@ static struct ipack_device *tpci200_slot_register(const char *board_name,
	if (slot_position >= TPCI200_NB_SLOT) {
	if (slot_position >= TPCI200_NB_SLOT) {
		pr_info("Slot [%s %d:%d] doesn't exist!\n",
		pr_info("Slot [%s %d:%d] doesn't exist!\n",
			TPCI200_SHORTNAME, tpci200_number, slot_position);
			TPCI200_SHORTNAME, tpci200_number, slot_position);
		goto out;
		return NULL;
	}
	}


	if (mutex_lock_interruptible(&tpci200->mutex))
	if (mutex_lock_interruptible(&tpci200->mutex))
		goto out;
		return NULL;


	if (tpci200->slots[slot_position].dev != NULL) {
	if (tpci200->slots[slot_position].dev != NULL) {
		pr_err("Slot [%s %d:%d] already installed !\n",
		pr_err("Slot [%s %d:%d] already installed !\n",
		       TPCI200_SHORTNAME, tpci200_number, slot_position);
		       TPCI200_SHORTNAME, tpci200_number, slot_position);
		goto out_unlock;
		goto err_unlock;
	}
	}


	dev = kzalloc(sizeof(struct ipack_device), GFP_KERNEL);
	dev = kzalloc(sizeof(struct ipack_device), GFP_KERNEL);
@@ -407,7 +407,7 @@ static struct ipack_device *tpci200_slot_register(const char *board_name,
		pr_info("Slot [%s %d:%d] Unable to allocate memory for new slot !\n",
		pr_info("Slot [%s %d:%d] Unable to allocate memory for new slot !\n",
			TPCI200_SHORTNAME,
			TPCI200_SHORTNAME,
			tpci200_number, slot_position);
			tpci200_number, slot_position);
		goto out_unlock;
		goto err_unlock;
	}
	}


	if (size > IPACK_BOARD_NAME_SIZE) {
	if (size > IPACK_BOARD_NAME_SIZE) {
@@ -440,15 +440,18 @@ static struct ipack_device *tpci200_slot_register(const char *board_name,
	dev->ops = &tpci200_bus_ops;
	dev->ops = &tpci200_bus_ops;
	tpci200->slots[slot_position].dev = dev;
	tpci200->slots[slot_position].dev = dev;


	if (ipack_device_register(dev) < 0) {
	if (ipack_device_register(dev) < 0)
		tpci200_slot_unregister(dev);
		goto err_unregister;
		kfree(dev);
	}


out_unlock:
	mutex_unlock(&tpci200->mutex);
	mutex_unlock(&tpci200->mutex);
out:
	return dev;
	return dev;

err_unregister:
	tpci200_slot_unregister(dev);
	kfree(dev);
err_unlock:
	mutex_unlock(&tpci200->mutex);
	return NULL;
}
}


static ssize_t tpci200_store_board(struct device *pdev, const char *buf,
static ssize_t tpci200_store_board(struct device *pdev, const char *buf,