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

Commit 58c1dd3a authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Amit Pundir
Browse files

ANDROID: memory_state_time: fix undefined behavior with missing DT properties

kernelci reports warnings about unintialized variable usage:

drivers/misc/memory_state_time.c:351:12: warning: 'lenf' is used uninitialized in this function [-Wuninitialized]
drivers/misc/memory_state_time.c:321:14: warning: 'lenb' is used uninitialized in this function [-Wuninitialized]

In both cases we try to continue without a DT property but use the
length that has not been assigned at this point. This rearranges the
code in the two functions to bail out earlier in case of an error.

The patch is needed for both android-common-4.9, 4.4 and 3.18.

Link: https://kernelci.org/build/id/591177f459b5147648b12d54/logs/


Fixes: ad3c02f8b3a5 ("ANDROID: Implement memory_state_time, used by qcom,cpubw")
Cc: James Carr <carrja@google.com>
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent f9b9dffc
Loading
Loading
Loading
Loading
+43 −35
Original line number Original line Diff line number Diff line
@@ -296,7 +296,11 @@ static int get_bw_buckets(struct device *dev)
	struct device_node *node = dev->of_node;
	struct device_node *node = dev->of_node;


	of_property_read_u32(node, NUM_SOURCES, &num_sources);
	of_property_read_u32(node, NUM_SOURCES, &num_sources);
	if (of_find_property(node, BW_TBL, &lenb)) {
	if (!of_find_property(node, BW_TBL, &lenb)) {
		pr_err("Missing %s property\n", BW_TBL);
		return -ENODATA;
	}

	bandwidths = devm_kzalloc(dev,
	bandwidths = devm_kzalloc(dev,
			sizeof(*bandwidths) * num_sources, GFP_KERNEL);
			sizeof(*bandwidths) * num_sources, GFP_KERNEL);
	if (!bandwidths)
	if (!bandwidths)
@@ -316,7 +320,7 @@ static int get_bw_buckets(struct device *dev)
		pr_err("Unable to read bandwidth table from device tree.\n");
		pr_err("Unable to read bandwidth table from device tree.\n");
		return ret;
		return ret;
	}
	}
	}

	curr_bw = 0;
	curr_bw = 0;
	num_buckets = lenb;
	num_buckets = lenb;
	return 0;
	return 0;
@@ -332,7 +336,11 @@ static int freq_buckets_init(struct device *dev)
	int ret, lenf;
	int ret, lenf;
	struct device_node *node = dev->of_node;
	struct device_node *node = dev->of_node;


	if (of_find_property(node, FREQ_TBL, &lenf)) {
	if (!of_find_property(node, FREQ_TBL, &lenf)) {
		pr_err("Missing %s property\n", FREQ_TBL);
		return -ENODATA;
	}

	lenf /= sizeof(*freq_buckets);
	lenf /= sizeof(*freq_buckets);
	freq_buckets = devm_kzalloc(dev, lenf * sizeof(*freq_buckets),
	freq_buckets = devm_kzalloc(dev, lenf * sizeof(*freq_buckets),
			GFP_KERNEL);
			GFP_KERNEL);
@@ -347,7 +355,7 @@ static int freq_buckets_init(struct device *dev)
		return ret;
		return ret;
	}
	}
	pr_debug("ret freq %d\n", ret);
	pr_debug("ret freq %d\n", ret);
	}

	num_freqs = lenf;
	num_freqs = lenf;
	curr_freq = freq_buckets[LOWEST_FREQ];
	curr_freq = freq_buckets[LOWEST_FREQ];