From patchwork Tue Jan 18 09:36:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 533129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CD7FC433EF for ; Tue, 18 Jan 2022 09:36:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344595AbiARJgS (ORCPT ); Tue, 18 Jan 2022 04:36:18 -0500 Received: from mga09.intel.com ([134.134.136.24]:22223 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240673AbiARJgS (ORCPT ); Tue, 18 Jan 2022 04:36:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642498578; x=1674034578; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=KOITIXo9rTTKwEPZruFQPM233i/+GJkiKbootFZI4Yk=; b=dCnX/rjWjXqd+Oq7IjcTE/TuNFmeA7fkbzVF4Lm0pfCzp7mvh1te/2Yz 4WrmvKcqrBvWvlKzYbNfGtJ1WbDLTKgJxX7xtw0YB1ZC6b9/gqKP8zbLc wg6Xi4hFiO1b5EyfckInLFTnnmWxPePm94FxRO/DX8HxLoibQ4uSSW7us Llmew3Yt7FGhRYqAuX8gg8xYvo3/fcG/xv7uJ83FWhiHGXlwLLizitjIc IL248D2JrCi8Uu0nQH+CmrVINVz359+h4KYMVqb3kYZa9JcZKXCDSCZpc WSglrx1tdcrktHjrFP27PcDzV8FDZBcPtM7kaeDZWG9KmFNo6/qXh062q g==; X-IronPort-AV: E=McAfee;i="6200,9189,10230"; a="244572557" X-IronPort-AV: E=Sophos;i="5.88,297,1635231600"; d="scan'208";a="244572557" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2022 01:36:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,297,1635231600"; d="scan'208";a="671790221" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 18 Jan 2022 01:36:15 -0800 From: Heikki Krogerus To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Rober?= =?utf-8?q?t_=C5=9Awi=C4=99cki?= , Mikhail Gavrilov Subject: [PATCH] usb: typec: Only attempt to link USB ports if there is fwnode Date: Tue, 18 Jan 2022 12:36:27 +0300 Message-Id: <20220118093627.74098-1-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The code that creates the links to the USB ports attached to a connector inside the system assumed that the ACPI nodes (fwnodes) always exist for the connectors, but it can not do that. There is no guarantee that every USB Type-C connector has ACPI device node representing it in the ACPI tables, and even if there are the nodes in the ACPI tables, the _STA method in those nodes may still return 0 (which means the device does not exist from ACPI PoW). This fixes NULL pointer dereference that happens if the nodes are missing. Reported-and-tested-by: Robert Święcki Reported-by: Mikhail Gavrilov Fixes: 730b49aac426 ("usb: typec: port-mapper: Convert to the component framework") Signed-off-by: Heikki Krogerus --- Hi guys, Mikhail, I got confirmation from Robert that the patch fixes the issue. thanks, --- drivers/usb/typec/port-mapper.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/port-mapper.c b/drivers/usb/typec/port-mapper.c index 07d307418b470..b6e0c6acc628c 100644 --- a/drivers/usb/typec/port-mapper.c +++ b/drivers/usb/typec/port-mapper.c @@ -56,6 +56,9 @@ int typec_link_ports(struct typec_port *con) { struct each_port_arg arg = { .port = con, .match = NULL }; + if (!has_acpi_companion(&con->dev)) + return 0; + bus_for_each_dev(&acpi_bus_type, NULL, &arg, typec_port_match); /* @@ -74,5 +77,6 @@ int typec_link_ports(struct typec_port *con) void typec_unlink_ports(struct typec_port *con) { - component_master_del(&con->dev, &typec_aggregate_ops); + if (has_acpi_companion(&con->dev)) + component_master_del(&con->dev, &typec_aggregate_ops); }