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

Commit 5fc17adf authored by Todd Poynor's avatar Todd Poynor Committed by Amit Pundir
Browse files

cpufreq: interactive: fix crash on error paths in get_tokenized_data



Use separate variable for error code, free proper pointer.

Change-Id: Ia83cccb195997789ac6afbf5b8761f7b278196d6
Reported-by: default avatarArve Hjønnevåg <arve@android.com>
Signed-off-by: default avatarTodd Poynor <toddpoynor@google.com>
parent 27474806
Loading
Loading
Loading
Loading
+6 −11
Original line number Diff line number Diff line
@@ -647,29 +647,26 @@ static unsigned int *get_tokenized_data(const char *buf, int *num_tokens)
	int i;
	int ntokens = 1;
	unsigned int *tokenized_data;
	int err = -EINVAL;

	cp = buf;
	while ((cp = strpbrk(cp + 1, " :")))
		ntokens++;

	if (!(ntokens & 0x1)) {
		tokenized_data = ERR_PTR(-EINVAL);
	if (!(ntokens & 0x1))
		goto err;
	}

	tokenized_data = kmalloc(ntokens * sizeof(unsigned int), GFP_KERNEL);
	if (!tokenized_data) {
		tokenized_data = ERR_PTR(-ENOMEM);
		err = -ENOMEM;
		goto err;
	}

	cp = buf;
	i = 0;
	while (i < ntokens) {
		if (sscanf(cp, "%u", &tokenized_data[i++]) != 1) {
			tokenized_data = ERR_PTR(-EINVAL);
		if (sscanf(cp, "%u", &tokenized_data[i++]) != 1)
			goto err_kfree;
		}

		cp = strpbrk(cp, " :");
		if (!cp)
@@ -677,10 +674,8 @@ static unsigned int *get_tokenized_data(const char *buf, int *num_tokens)
		cp++;
	}

	if (i != ntokens) {
		tokenized_data = ERR_PTR(-EINVAL);
	if (i != ntokens)
		goto err_kfree;
	}

	*num_tokens = ntokens;
	return tokenized_data;
@@ -688,7 +683,7 @@ static unsigned int *get_tokenized_data(const char *buf, int *num_tokens)
err_kfree:
	kfree(tokenized_data);
err:
	return tokenized_data;
	return ERR_PTR(err);
}

static ssize_t show_target_loads(