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

Commit e9ec7f35 authored by Jiri Slaby's avatar Jiri Slaby Committed by Matthew Garrett
Browse files

X86: intel_ips, check for kzalloc properly



Stanse found that there are two NULL checks missing in ips_monitor. So
check their value too and bail out appropriately if the allocation
failed.

While at it, add one more kfree to the fail path. It is not necessary
now, but may be needed in the future when a new allocation is added.
And for completeness.

Also remove unneeded initialization of the variables. They are all set
right after their declaration.

Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
Signed-off-by: default avatarMatthew Garrett <mjg@redhat.com>
Acked-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent dfec5c48
Loading
Loading
Loading
Loading
+5 −4
Original line number Original line Diff line number Diff line
@@ -920,9 +920,8 @@ static int ips_monitor(void *data)
	struct timer_list timer;
	struct timer_list timer;
	unsigned long seqno_timestamp, expire, last_msecs, last_sample_period;
	unsigned long seqno_timestamp, expire, last_msecs, last_sample_period;
	int i;
	int i;
	u32 *cpu_samples = NULL, *mchp_samples = NULL, old_cpu_power;
	u32 *cpu_samples, *mchp_samples, old_cpu_power;
	u16 *mcp_samples = NULL, *ctv1_samples = NULL, *ctv2_samples = NULL,
	u16 *mcp_samples, *ctv1_samples, *ctv2_samples, *mch_samples;
		*mch_samples = NULL;
	u8 cur_seqno, last_seqno;
	u8 cur_seqno, last_seqno;


	mcp_samples = kzalloc(sizeof(u16) * IPS_SAMPLE_COUNT, GFP_KERNEL);
	mcp_samples = kzalloc(sizeof(u16) * IPS_SAMPLE_COUNT, GFP_KERNEL);
@@ -931,7 +930,8 @@ static int ips_monitor(void *data)
	mch_samples = kzalloc(sizeof(u16) * IPS_SAMPLE_COUNT, GFP_KERNEL);
	mch_samples = kzalloc(sizeof(u16) * IPS_SAMPLE_COUNT, GFP_KERNEL);
	cpu_samples = kzalloc(sizeof(u32) * IPS_SAMPLE_COUNT, GFP_KERNEL);
	cpu_samples = kzalloc(sizeof(u32) * IPS_SAMPLE_COUNT, GFP_KERNEL);
	mchp_samples = kzalloc(sizeof(u32) * IPS_SAMPLE_COUNT, GFP_KERNEL);
	mchp_samples = kzalloc(sizeof(u32) * IPS_SAMPLE_COUNT, GFP_KERNEL);
	if (!mcp_samples || !ctv1_samples || !ctv2_samples || !mch_samples) {
	if (!mcp_samples || !ctv1_samples || !ctv2_samples || !mch_samples ||
			!cpu_samples || !mchp_samples) {
		dev_err(&ips->dev->dev,
		dev_err(&ips->dev->dev,
			"failed to allocate sample array, ips disabled\n");
			"failed to allocate sample array, ips disabled\n");
		kfree(mcp_samples);
		kfree(mcp_samples);
@@ -939,6 +939,7 @@ static int ips_monitor(void *data)
		kfree(ctv2_samples);
		kfree(ctv2_samples);
		kfree(mch_samples);
		kfree(mch_samples);
		kfree(cpu_samples);
		kfree(cpu_samples);
		kfree(mchp_samples);
		kthread_stop(ips->adjust);
		kthread_stop(ips->adjust);
		return -ENOMEM;
		return -ENOMEM;
	}
	}