Skip to content

Commit

Permalink
powercap: intel_rapl: Fix a NULL pointer dereference
Browse files Browse the repository at this point in the history
[ Upstream commit 2d1f500 ]

A NULL pointer dereference is triggered when probing the MMIO RAPL
driver on platforms with CPU ID not listed in intel_rapl_common CPU
model list.

This is because the intel_rapl_common module still probes on such
platforms even if 'defaults_msr' is not set after commit 1488ac9
("powercap: intel_rapl: Allow probing without CPUID match"). Thus the
MMIO RAPL rp->priv->defaults is NULL when registering to RAPL framework.

Fix the problem by adding sanity check to ensure rp->priv->rapl_defaults
is always valid.

Fixes: 1488ac9 ("powercap: intel_rapl: Allow probing without CPUID match")
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Cc: 6.5+ <stable@vger.kernel.org> # 6.5+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
zhang-rui authored and gregkh committed Apr 3, 2024
1 parent 5c993e4 commit 2f73cf2
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/powercap/intel_rapl_common.c
Expand Up @@ -759,6 +759,11 @@ static int rapl_config(struct rapl_package *rp)
default:
return -EINVAL;
}

/* defaults_msr can be NULL on unsupported platforms */
if (!rp->priv->defaults || !rp->priv->rpi)
return -ENODEV;

return 0;
}

Expand Down

0 comments on commit 2f73cf2

Please sign in to comment.