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

Commit bdd8d351 authored by Nicholas Troast's avatar Nicholas Troast
Browse files

power: pmic-voter: fix memory leak in create_votable



Memory is leaked when an ERR_PTR is returned after memory has been
allocated for the votable. Fix this by allocating memory after all
the parameters have been validated.

CRs-Fixed: 957574
Change-Id: I0a3ba9dcf3d6138694677874b9b19b6cdd434a07
Signed-off-by: default avatarNicholas Troast <ntroast@codeaurora.org>
parent 64182585
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -223,11 +223,7 @@ struct votable *create_votable(struct device *dev, const char *name,
					)
{
	int i;
	struct votable *votable = devm_kzalloc(dev, sizeof(struct votable),
							GFP_KERNEL);

	if (!votable)
		return ERR_PTR(-ENOMEM);
	struct votable *votable;

	if (!callback) {
		dev_err(dev, "Invalid callback specified for voter\n");
@@ -244,6 +240,10 @@ struct votable *create_votable(struct device *dev, const char *name,
		return ERR_PTR(-EINVAL);
	}

	votable = devm_kzalloc(dev, sizeof(struct votable), GFP_KERNEL);
	if (!votable)
		return ERR_PTR(-ENOMEM);

	votable->dev = dev;
	votable->name = name;
	votable->num_clients = num_clients;