Unverified Commit aab87476 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!15769 gpio: aggregator: protect driver attr handlers against module unload

parents 500b18be 68612064
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -173,10 +173,15 @@ static ssize_t new_device_store(struct device_driver *driver, const char *buf,
	struct platform_device *pdev;
	int res, id;

	if (!try_module_get(THIS_MODULE))
		return -ENOENT;

	/* kernfs guarantees string termination, so count + 1 is safe */
	aggr = kzalloc(sizeof(*aggr) + count + 1, GFP_KERNEL);
	if (!aggr)
		return -ENOMEM;
	if (!aggr) {
		res = -ENOMEM;
		goto put_module;
	}

	memcpy(aggr->args, buf, count + 1);

@@ -215,6 +220,7 @@ static ssize_t new_device_store(struct device_driver *driver, const char *buf,
	}

	aggr->pdev = pdev;
	module_put(THIS_MODULE);
	return count;

remove_table:
@@ -229,6 +235,8 @@ static ssize_t new_device_store(struct device_driver *driver, const char *buf,
	kfree(aggr->lookups);
free_ga:
	kfree(aggr);
put_module:
	module_put(THIS_MODULE);
	return res;
}

@@ -257,13 +265,19 @@ static ssize_t delete_device_store(struct device_driver *driver,
	if (error)
		return error;

	if (!try_module_get(THIS_MODULE))
		return -ENOENT;

	mutex_lock(&gpio_aggregator_lock);
	aggr = idr_remove(&gpio_aggregator_idr, id);
	mutex_unlock(&gpio_aggregator_lock);
	if (!aggr)
	if (!aggr) {
		module_put(THIS_MODULE);
		return -ENOENT;
	}

	gpio_aggregator_free(aggr);
	module_put(THIS_MODULE);
	return count;
}
static DRIVER_ATTR_WO(delete_device);