From nobody Sun Feb 8 02:26:09 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0D9A36A025 for ; Thu, 15 Jan 2026 10:37:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768473436; cv=none; b=CLwcNixbts5LZK6bqF29uRYMRB/ZNPRfRPiTks4MU4PrAyihv0tj28j9T+znXerme5iNXGUArwnxo0UQCHhg/iWVXca6n0oXzaGhfqJbyJsweGyI2r6NSquoDHfL0TDpg2HvXGQUAbYm12S5e9x0g23pqY6ESHb60UiW4gowM18= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768473436; c=relaxed/simple; bh=mroer21tyn+VD73El7nXuBQ45D8aT09v1u5rNLXbTnY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=E+/r4lUPGdESw8OQczpj7TZLRHF50SduZm+BAX7K30zH/MaaEDOuOGwpvaH5z5eii72JmkBFqvxK1Nh0RCFD4yvSvfpznLjbJZl7mr+cVBKO96b322U8YL+eHoZ2NVFmmTS19i2EDP2KC7texbqqGTqZ4lfcWpdaX4eac8PGLss= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=g+A+7HsD; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="g+A+7HsD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768473433; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=nxAyT8OzTNULMr7XLos5FaceRIYaialub9HWZHZwsXw=; b=g+A+7HsDqSeunZSFF2QaXpAF/+JlifPZYaZJJmLOebvc5rf1JJo8/0ko7L+ohSXwSq6f85 UxXQVzrQXA8xXNqVCG0nonzPEQW007941odfyMZIBbGVdZuYT6oXH0Qgi5toDnFMt1H2v/ iramW/heQ40Oz6itYClv19FltF2SxWk= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-491-Rm2HCpxvM2ywjPe_ZzUfAA-1; Thu, 15 Jan 2026 05:37:12 -0500 X-MC-Unique: Rm2HCpxvM2ywjPe_ZzUfAA-1 X-Mimecast-MFC-AGG-ID: Rm2HCpxvM2ywjPe_ZzUfAA_1768473431 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 06F4218005B4; Thu, 15 Jan 2026 10:37:11 +0000 (UTC) Received: from mrout-thinkpadp16vgen1.punetw6.csb (unknown [10.74.64.47]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 50AF71955F22; Thu, 15 Jan 2026 10:37:06 +0000 (UTC) From: Malaya Kumar Rout To: lukasz.luba@arm.com Cc: mrout@redhat.com, malayarout91@gmail.com, "Rafael J. Wysocki" , Len Brown , Pavel Machek , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] PM: EM: Fix NULL pointer dereference in em_create_pd() Date: Thu, 15 Jan 2026 16:07:00 +0530 Message-ID: <20260115103700.177997-1-mrout@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" The get_cpu_device() function can return NULL if the CPU device is not registered. However, the code in em_create_pd() dereferences the returned pointer without checking for NULL, which can lead to a kernel panic during energy model initialization. Add a NULL check before dereferencing cpu_dev. If get_cpu_device() returns NULL, return -ENODEV and properly clean up allocated resources through the existing error path. This issue was found by code inspection. The same function is correctly handled with NULL checking in em_cpu_get() at line 555-557. Fixes: 1bc138c62295 ("PM / EM: add support for other devices than CPUs in E= nergy Model") Signed-off-by: Malaya Kumar Rout --- kernel/power/energy_model.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 11af9f64aa82..3971743d7e67 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -466,6 +466,10 @@ static int em_create_pd(struct device *dev, int nr_sta= tes, if (_is_cpu_device(dev)) for_each_cpu(cpu, cpus) { cpu_dev =3D get_cpu_device(cpu); + if (!cpu_dev) { + ret =3D -ENODEV; + goto free_pd_table; + } cpu_dev->em_pd =3D pd; } =20 --=20 2.52.0