From nobody Sat Jul 11 00:51:32 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6B3B3E48C for ; Fri, 10 May 2024 18:43:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715366620; cv=none; b=VamJIGp6h4HZ0if7+FMXkIyjW/1Nmo7mG1SgtT46CCOdtCF1MQVgxduBRl8vmzN/hyJ+VHoOG9YQw+DBhIWznYhMAJCjL9pEz5D92DN8u/8KhcKHE9kDAZLcQW/igyNtJXWp/jSVbHo/hnV6J8b8pOYnVkGidKaL102j7ewKcGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715366620; c=relaxed/simple; bh=bPIwwSWz7vhLPkw2Y7IUkySooH/UFfl9RPgbQvpMT1Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PGA50l/jsWK2yOwD+ScwBdWbwZYCWdE6eoboDdi38hQPtKeqCPoYV9CuGL6knzVOaG44LdjS7dOZauWX8mB/yQfBVnijlyVc0xqQkfwI5DR9iDNo7OqcqOoAsOjr1inQbQ9Q5wHCTkYols1NS3OHRBFtNgKkaSiKgqaMtmoUVUA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=EMaS2WYk; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="EMaS2WYk" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61be8f7ed6eso27405747b3.0 for ; Fri, 10 May 2024 11:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715366618; x=1715971418; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=3leKVp6DbOZKt/BkP9hZjqxScIgMDd3b3vJx/j0Aby4=; b=EMaS2WYkbIhvSmYlF4THbt56fWrbxMNAFU61GNmmeRwGXAf3/nXb8b42DdQcWrE4+A CvD1v/fcygFSRp99Y31jGCzjTzO+iwU5piRu7jVfVHPAH4fsD1xCYMr8cVUgudkhBKyD Vv6avvdbT9eJm+BnZ08aI0X7HohEgF9RHWgvexzVUqjsyV6WtEAtzMyHP0T1E0dxKcra ARkBdnBqfZ+CGojc4ls3mLxrCkPuzBMLQfiEgbEHU0T3yIVJ+mDiDkWbHdidHJ8fQhJD V4RI7zvETjauRhFNaXIJLGKjOVBF7Pt4dehm4SKoI8vRspSHYSfF3lC1lU3FL79CRYsP L/9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715366618; x=1715971418; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3leKVp6DbOZKt/BkP9hZjqxScIgMDd3b3vJx/j0Aby4=; b=JkEdx5QtOn16qwkqWoE1QqhfIlYDfvEPk7h/6Qj3bMiH0Ijl9xe9aBYB1bOoJ/eKm8 sx7HwI2X/MTyg+gtAYQ7VXWbzPiYAbZA3kHz5DD5HquVzDnBoeqk5oMTEgTEdTBWP/v8 hAa5I9HeOTH9+ndK8yMGYgznWm7XBBkxCiRQUPJSLbIOqHVnBfohgiVietpCpzXLIT1q vwD7LI4cxK/kqwRxwTBeaf1iXeyPS0IhISKye8dvhKY+AxcDci2W1d1+fQjcjbUOmQLQ 4czgnTj5Wa5DD5WqaVWW0TOq8aJCEk5fgO4AyCttE3zyZ4RO6XmsfDpsThlPY6Uf0odR 7SyA== X-Forwarded-Encrypted: i=1; AJvYcCWBOvTRCZdbOhwN+45H8BahiUJQJ4N8DeiQeB2UkbiWlCuWKS87ZGwn+U17CPLQgKukANEjiGsGm2VzKTZnibxykxVJIGE1YS3MhhqP X-Gm-Message-State: AOJu0Yx6JC2zb2etoV3q5IIUJGjW0k246DuZ6jd/Psfzc84Fj9TYEQ3e oSewWuqmv9Xzm0hrV3RFsJxLKj4C7cjySKp1R84vmYJc/+scSQQ2euLXyBBAhpqasdY29DBVbiD Bgg== X-Google-Smtp-Source: AGHT+IH0Hl7sTOqR41zDK1Dxc6Amfcy0YB0Fkd2Xj5M07oxreTYb6CYyg15guWzK5gZbo9fvojMWUZHuFdk= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:690c:6202:b0:611:5a9d:bb0e with SMTP id 00721157ae682-622af90c63bmr9600407b3.4.1715366617882; Fri, 10 May 2024 11:43:37 -0700 (PDT) Date: Fri, 10 May 2024 18:43:21 +0000 In-Reply-To: <20240510184324.2944101-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240510184324.2944101-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog Message-ID: <20240510184324.2944101-2-jthies@google.com> Subject: [PATCH v4 1/4] usb: typec: ucsi: Fix null pointer dereference in trace From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org, Benson Leung Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Abhishek Pandit-Subedi ucsi_register_altmode checks IS_ERR for the alt pointer and treats NULL as valid. When CONFIG_TYPEC_DP_ALTMODE is not enabled, ucsi_register_displayport returns NULL which causes a NULL pointer dereference in trace. Rather than return NULL, call typec_port_register_altmode to register DisplayPort alternate mode as a non-controllable mode when CONFIG_TYPEC_DP_ALTMODE is not enabled. Reviewed-by: Benson Leung Reviewed-by: Heikki Krogerus Signed-off-by: Jameson Thies Signed-off-by: Abhishek Pandit-Subedi --- Changes in V4: - Updated commit message. Changes in V3: - Returns typec_port_register_altmode call from ucsi_register_displayport when CONFIG_TYPEC_DP_ALTMODE is not enabled. Updated commit message. Changes in V2: - Checks for error response from ucsi_register_displayport when registering DisplayPort alternate mode. drivers/usb/typec/ucsi/ucsi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index c4d103db9d0f8..f66224a270bc6 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -496,7 +496,7 @@ ucsi_register_displayport(struct ucsi_connector *con, bool override, int offset, struct typec_altmode_desc *desc) { - return NULL; + return typec_port_register_altmode(con->port, desc); } =20 static inline void --=20 2.45.0.118.g7fe29c98d7-goog From nobody Sat Jul 11 00:51:32 2026 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A52A47A62 for ; Fri, 10 May 2024 18:43:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715366624; cv=none; b=lLSFekL+VlRlYcMkq0YDIdEXyNg5vQY4cvIItu64AohuPs5A58w9ZlhQR+9UPisLzjlX+Ay8bxZUyEKyQTbrxrM1w+BGAaX8Zmbvy2iOL1vzQMFypaHPStypp2FPlUMUeVmKvBwGWdUabSBulDm/bZesxKUdS0V9WLUDgqGY9Ic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715366624; c=relaxed/simple; bh=gQji9l12Fjk6vAy1gBuYFgvwCdzi4ZJBVjEkxA6DHUk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TB8lYzIyB0/Ha1QOluOuBWBLSu59y0tGyrOm3fnpnacCVk0R6YeVUTI3Q/N28kTEwZwKnD7n+/BiGq/v+JPG5x6XBhUAcn3m7WoRFBtQCJN2IHhZ7RIB3t1/7wbs6IUj+z2GCWz50UY8y5WXLBkRbzppqYlzRg84lXQdRWgnJVU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=UPXYbBMN; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UPXYbBMN" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-ddaf2f115f2so3614587276.3 for ; Fri, 10 May 2024 11:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715366621; x=1715971421; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=gcZTWRljQX/x9I6RAMAcoKUh92qzwt0cLFIO8/Y0bdA=; b=UPXYbBMNcl0BzrwD4yEBs5E74eyC75moFzXMQGQAWs/ne1LdCUwkaXDMEpMvCaS4yB 2JIkMxr4JLhsNqDFvdeejx0ODnnp1D6Bze4jcyWypPWJsmfXhe6+kwiZQCb5nHh0OAys 5plfXXpwygQj3ebmTZ+2q5ynH9I+ccNjwJDHqQpTZaWN7ERsV0s9H72E8JiN6fVp3f8a T8agyjhODp1RLJtaDfEsFhx9R6f0fcZsoHi9rivQiEzdZpG4iTiDzBOg8W+19VX5a6Sv bchQtXMZnRpvX6gvcQ7rUzqzgdeFKkdyKVZ/IyhVQU7bDc8GBAq7xyD3tndI2KbixIGf NBrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715366621; x=1715971421; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gcZTWRljQX/x9I6RAMAcoKUh92qzwt0cLFIO8/Y0bdA=; b=QMIyz3Qk/SVTGVR1ioAGG68jsVjReYsNpaFM+e90soCeAhPc6TL8EvluEG4cAvv0Wy Ehum762NZAgOqGKGwK1lgGuP3MLARvKR9EbMkMe18EEUrj1iGk2QyKTkuE4VQcJyMCXO JUveCMKqlpTuCbH3SINaiu84Zsnwq7WTyfgs9Udbzc5BqucVmWEqWTYrQtrTNwItJJWu mcDHddQvlohXlHdbRJMhOtgi2AqPGLEpUI633s2f746a8QF4e5cwaUiq1grV0by4/Iqb lrUdApPJk52MpzFQunpR2BvbUq03WPYlTGp1LWUnBfQBj+F1v5vWlbot5/K2yTz8So9D g0fg== X-Forwarded-Encrypted: i=1; AJvYcCWi9sEMWaEonEin764rd1BBkgaf0RDtT1xT7j+j8pWSssierqu3cEfaHQfOU2lnA5rbrmca4zlugDXT//mX16xckGUhsRduxkCuSrDb X-Gm-Message-State: AOJu0YzHaO1w3Mwhv/mhSAFHSmBM9XafNMUP+TwaTq6j7edQThnJf2BN MBfNoIqTfYut0KOTnV0Ynng1Rd0C3hCt1TD8c8ngCEeP16fV+uY7UuzZSz8rHeLu4xXcRGOAb9A Sgg== X-Google-Smtp-Source: AGHT+IEX+Y0TwfXDXyAK2FWGkX+Yp7DciNo2SWMVEaaeHqCrTSftQYF1VowZjG+ms1EStcbrcZ9NIePZn7Q= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a25:fb06:0:b0:dce:5218:c89b with SMTP id 3f1490d57ef6-dee4f3595b8mr317092276.5.1715366621008; Fri, 10 May 2024 11:43:41 -0700 (PDT) Date: Fri, 10 May 2024 18:43:22 +0000 In-Reply-To: <20240510184324.2944101-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240510184324.2944101-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog Message-ID: <20240510184324.2944101-3-jthies@google.com> Subject: [PATCH v4 2/4] usb: typec: Update sysfs when setting ops From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org, Benson Leung Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Abhishek Pandit-Subedi When adding altmode ops, update the sysfs group so that visibility is also recalculated. Reviewed-by: Heikki Krogerus Reviewed-by: Benson Leung Signed-off-by: Jameson Thies Signed-off-by: Abhishek Pandit-Subedi --- Changes in V4: - None. Changes in V3: - None. Changes in V2: - None. drivers/usb/typec/altmodes/displayport.c | 2 +- drivers/usb/typec/class.c | 18 +++++++++++++++++- drivers/usb/typec/ucsi/displayport.c | 2 +- include/linux/usb/typec.h | 3 +++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/a= ltmodes/displayport.c index 596cd4806018b..92cc1b1361208 100644 --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c @@ -746,7 +746,7 @@ int dp_altmode_probe(struct typec_altmode *alt) dp->alt =3D alt; =20 alt->desc =3D "DisplayPort"; - alt->ops =3D &dp_altmode_ops; + typec_altmode_set_ops(alt, &dp_altmode_ops); =20 if (plug) { plug->desc =3D "Displayport"; diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 9610e647a8d48..9262fcd4144f8 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -467,6 +467,22 @@ static const struct attribute_group *typec_altmode_gro= ups[] =3D { NULL }; =20 +/** + * typec_altmode_set_ops - Set ops for altmode + * @adev: Handle to the alternate mode + * @ops: Ops for the alternate mode + * + * After setting ops, attribute visiblity needs to be refreshed if the alt= ernate + * mode can be activated. + */ +void typec_altmode_set_ops(struct typec_altmode *adev, + const struct typec_altmode_ops *ops) +{ + adev->ops =3D ops; + sysfs_update_group(&adev->dev.kobj, &typec_altmode_group); +} +EXPORT_SYMBOL_GPL(typec_altmode_set_ops); + static int altmode_id_get(struct device *dev) { struct ida *ids; @@ -2317,7 +2333,7 @@ void typec_port_register_altmodes(struct typec_port *= port, continue; } =20 - alt->ops =3D ops; + typec_altmode_set_ops(alt, ops); typec_altmode_set_drvdata(alt, drvdata); altmodes[index] =3D alt; index++; diff --git a/drivers/usb/typec/ucsi/displayport.c b/drivers/usb/typec/ucsi/= displayport.c index d9d3c91125ca8..eb7b8d6e47d00 100644 --- a/drivers/usb/typec/ucsi/displayport.c +++ b/drivers/usb/typec/ucsi/displayport.c @@ -337,7 +337,7 @@ struct typec_altmode *ucsi_register_displayport(struct = ucsi_connector *con, dp->con =3D con; dp->alt =3D alt; =20 - alt->ops =3D &ucsi_displayport_ops; + typec_altmode_set_ops(alt, &ucsi_displayport_ops); typec_altmode_set_drvdata(alt, dp); =20 return alt; diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index b35b427561ab5..549275f8ac1b3 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -167,6 +167,9 @@ struct typec_port *typec_altmode2port(struct typec_altm= ode *alt); =20 void typec_altmode_update_active(struct typec_altmode *alt, bool active); =20 +void typec_altmode_set_ops(struct typec_altmode *alt, + const struct typec_altmode_ops *ops); + enum typec_plug_index { TYPEC_PLUG_SOP_P, TYPEC_PLUG_SOP_PP, --=20 2.45.0.118.g7fe29c98d7-goog From nobody Sat Jul 11 00:51:32 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE5C8487B6 for ; Fri, 10 May 2024 18:43:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715366626; cv=none; b=NnLjfdRDCQJomywxntx/ng6W9Lol/nxZQ1DXaC3DEm5KLEFtQZEzazxhqYOFxEXbD5nmV9UmtTXlOmyEdtKfgAxif4ViQEVQ/ZCkDHQyfCe6I/uZ1BkyfWIyc/SraC/s22XxDwnvPzVV9xUrhikhS9aoxLxyLBNyFGfrXUZ5YG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715366626; c=relaxed/simple; bh=5Dxt8M/uMnrYaCujm6SYe3p0Nct6vbEeAdJLQT8qgX4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=p76alnaEfpA/HR6kmywmUSYhL7f/Bnl313ckOvb2rqkRfHRWkV+E58b/V3/JP0/NZ98h1u4jcsWyOYrdQcFdR0Pk1R4UOGNI3VOnjUOSHVmgvFlJsK5w1stut+YxTuuM/9NtR3y2vUh1ctfcAmQbh3iK/KNaSOV/75yP6oYz3uk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=BVGADxvI; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BVGADxvI" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-620a2321b0fso30877917b3.3 for ; Fri, 10 May 2024 11:43:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715366624; x=1715971424; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Ibv/f3Jsw2CQCASuGotHQItld+LQXS/bJ8cmbunskpI=; b=BVGADxvIsseFytloloa6J8ZK/n6MXRxCP3qoLi7FVIbuxg5FCrSc4u+Z32RmEqeujL C/cx4acpAE93nY41Nb3SqOAKTfyjZFQ/DsTxYaoGGhkYPLIvf917udWjPZM/6F69YlF3 f5HArZZXzjJoNwEAdZhNWTpqbb1UNQlQunPJ74Y7pzsN0F92hi7PVvYTtbNnJQq+Oh7O MtLmEvHgWH9LrjeVVK9m1j+jseFa5kKmuapNBS8yNM6JqAjkmuTj4xEOkKKuE/NoW6Dy T2e0WEwODDquHxxrtnzYzEMrkdVjomt3RKVd1ZRR1F59no1z1BHbmXeOzHoNa/a0OYNU emQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715366624; x=1715971424; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ibv/f3Jsw2CQCASuGotHQItld+LQXS/bJ8cmbunskpI=; b=Ael/deWePa9LZ3ioyHQI8QaBkkpV+Ocmrf0WHn9fDyIg1dWzSynBvJpeZatH2wMUy8 QFqdoUJpWZ22lP383FvcJeBRbCVO8nOnulCBRjdqOUImSMlDzeVNiRj8rfK9X07obeN2 zDBNplPeo6kIxbJ2rP7rVVChW6EYaLE3ZnHfWjSbqdXyQjhZUhUE83Tsnb5jpQl/ar1u OTaL6PeDP4P0ZGk0+pQjHeWiAll0ZhKOEci+EwpZbqUsAi2UdBz6DVN4ICO1KhX36tsf OQ92UFitq13taXUlp26Spm55UnWEY/FMGcmKbqnCzB4cpkkKux5gFw/iLiBvWkxPilct lQLQ== X-Forwarded-Encrypted: i=1; AJvYcCW2uB4lWkug5tN3V5Qh76937J4EFezRsJDjsTCA+OjiweXn3mj/RD9qXwJJIvQX+UlkbM+JRcpNWGq123lds3VCdJeUpqDKvQkyXonY X-Gm-Message-State: AOJu0YyYLqPtoe3q5PPfKqnfMfbcNX72GYhUD8OaFRS8MCPPy3x+hVzS DiJrM40ORhN3KK0II+2CbX9g3CK26TWVDP5eHoY96LThyk36lSlqhUTQqcAWRcT3wLKmQAHRO4u 5Vg== X-Google-Smtp-Source: AGHT+IGDfBKNUEYIqbIlS5Fkvoe+iha8Qx5p07lHU3gwnZ3n5tfA9OQISwkzlfUYlssG+VExqcdQVtPLK4A= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:690c:6c0e:b0:61b:ec22:8666 with SMTP id 00721157ae682-622afd96b2fmr7843577b3.0.1715366623917; Fri, 10 May 2024 11:43:43 -0700 (PDT) Date: Fri, 10 May 2024 18:43:23 +0000 In-Reply-To: <20240510184324.2944101-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240510184324.2944101-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog Message-ID: <20240510184324.2944101-4-jthies@google.com> Subject: [PATCH v4 3/4] usb: typec: ucsi: Delay alternate mode discovery From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org, Benson Leung Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Delay the ucsi_check_altmodes task to be inline with surrounding partner tasks. This allows partner, cable and identity discovery to complete before alternate mode registration. With that order, alternate mode discovery can be used to indicate the ucsi driver has completed discovery. Reviewed-by: Heikki Krogerus Reviewed-by: Benson Leung Signed-off-by: Jameson Thies --- Changes in V4: - None. Changes in V3: - None. Changes in V2: - None. drivers/usb/typec/ucsi/ucsi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index cb52e7b0a2c5c..bb6e57064513d 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -963,7 +963,7 @@ static void ucsi_pwr_opmode_change(struct ucsi_connecto= r *con) con->rdo =3D con->status.request_data_obj; typec_set_pwr_opmode(con->port, TYPEC_PWR_MODE_PD); ucsi_partner_task(con, ucsi_get_src_pdos, 30, 0); - ucsi_partner_task(con, ucsi_check_altmodes, 30, 0); + ucsi_partner_task(con, ucsi_check_altmodes, 30, HZ); ucsi_partner_task(con, ucsi_register_partner_pdos, 1, HZ); break; case UCSI_CONSTAT_PWR_OPMODE_TYPEC1_5: @@ -1247,7 +1247,7 @@ static void ucsi_handle_connector_change(struct work_= struct *work) } =20 if (con->status.change & UCSI_CONSTAT_CAM_CHANGE) - ucsi_partner_task(con, ucsi_check_altmodes, 1, 0); + ucsi_partner_task(con, ucsi_check_altmodes, 1, HZ); =20 out_unlock: mutex_unlock(&con->lock); --=20 2.45.0.118.g7fe29c98d7-goog From nobody Sat Jul 11 00:51:32 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FEA24D135 for ; Fri, 10 May 2024 18:43:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715366629; cv=none; b=EfUCGejJCFXN1WGDX17UwKcsMncLCVCqJpp9XxOLeKyxA3+hFrOtlsmmOhOJUtRY4JiHC8ynocN9avg56D5FlDuzC5kQbqW7a6LRHTPhr1sLvysNYoxtX+o3kmgsiQfAkkPrhg/tu1HQvx66ug2qa5zE/M/fHLRQitoPnwe95tY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715366629; c=relaxed/simple; bh=R0kPcz2z7KHQtcT+DCQun4RPsuErPgcBNGZMQbxuRmI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=nW0SSYohORbv2KtSq/nfvp5rWV3x6dpRGdhnHCWI6CAx4/y4SxNsztgisFpuEvMXTgsGXD0aZnYj6p4oqwmwUO802xV0qv5oA/Wl8CAbvE/skcgG+/m3U1VNuQ87zRdMkW+0d8Xn4cR0/x1IW9ywxdEfgQDyB17c2rpK+clLRQY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=XhgFULAD; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XhgFULAD" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-62035d9ecc4so40628157b3.1 for ; Fri, 10 May 2024 11:43:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715366627; x=1715971427; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5TEblfXliubmthqHAqJA2jNdtqm1t1yD50gCYv7pJus=; b=XhgFULADE46oqk5FpKzQer23oOo97i7TBoKoeteoHxUBHNuHCPWnXvKdZNQrVjzI9g /cU/NV3jJ6FhUVepkLpNnw/MUqZ9jRrP9zsJjFxDHwexN1R1ghP1FwZliTXMDWNk3E7b 1QJmp3pPrp/41fg2wC3N3mMoj1ed9iTvxWNG6z8WerFrmT+UrdiEzD1faLvpCQx3GwPm yp1c4ZATrUnxu3OjSAS3px7eDx0ICMC5tevh6MkcjbwmchHB94CcHbRxznmJqmLbu5Uk LxuksmOr67lIagAgYJ44qsqCQ9rzJ7wFR9A2wlj/JkVJlcQ5Ljgnqw/5P/khHRCGmdAz 1M1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715366627; x=1715971427; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5TEblfXliubmthqHAqJA2jNdtqm1t1yD50gCYv7pJus=; b=siNpX9GTVuu80WlG8xoMYylO8tphvQhjkT+JnFsekOeQI1/C+jcLROyGO3kUWi+GYL iZ8EQLmGtXr3X1ZGybBn+47iaxcEpVhosOvy4nvtYJsVIRFK/ZuIZYZQ0WklzeZeF9Yq 3a0mR6SFjkVJ6pEy2hjDr056tpoUkv4RkETVspBhdXZ4kriwEiGEaQNKJMqPSookqNZc IYnL++SrijUy6v5C1RPezf+5myFHrJ2KkN0FK49g3z5lRixWyAZ4ZlbMENyPYvp5gfxT wnauJw6Osjtj70QiZpZ+dt9/iTxp2WKMwQ5Dji+pZmC759Q8v6ZlIYOWgNiIewyzGI// ejfw== X-Forwarded-Encrypted: i=1; AJvYcCUQBakLxV71klYvJiOzMVS7sWsjwL7blrW4Nkgc0iXRMJ2fSp83yFskC2y81apiUXGQpiA3bbjb5EmobOPNyO+gdEzP20uHdTMHo2DZ X-Gm-Message-State: AOJu0YyW53XT6+SXto/Hlsb06slgFPY/q56jcZbR3wlS/iJcgQOSQIpA vplseyQGCQYSlGChweKvCx7TApecUBdlxXSokOGAc8rMckKiBpikp7mmt/PILWz73bolF8Eg2p2 gpQ== X-Google-Smtp-Source: AGHT+IGaWgy+lzvqz9wTSsHNfbW5bue9orgmN1BHek+1YZUAMaba3g5YRlXLvCXcathhN4gsL6Nmrz7YeF4= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:690c:3801:b0:61b:ec81:3f3b with SMTP id 00721157ae682-622b0038dfbmr8623737b3.5.1715366626864; Fri, 10 May 2024 11:43:46 -0700 (PDT) Date: Fri, 10 May 2024 18:43:24 +0000 In-Reply-To: <20240510184324.2944101-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240510184324.2944101-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog Message-ID: <20240510184324.2944101-5-jthies@google.com> Subject: [PATCH v4 4/4] usb: typec: ucsi: Always set number of alternate modes From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org, Benson Leung Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Providing the number of known alternate modes allows user space to determine when device registration has completed. Always register a number of known alternate modes for the partner and cable plug, even when the number of supported alternate modes is 0. Reviewed-by: Heikki Krogerus Reviewed-by: Benson Leung Signed-off-by: Jameson Thies --- Changes in V4: - None. Changes in V3: - None. Changes in V2: - None. drivers/usb/typec/ucsi/ucsi.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index bb6e57064513d..52a14bfe4107e 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -812,10 +812,11 @@ static int ucsi_check_altmodes(struct ucsi_connector = *con) /* Ignoring the errors in this case. */ if (con->partner_altmode[0]) { num_partner_am =3D ucsi_get_num_altmode(con->partner_altmode); - if (num_partner_am > 0) - typec_partner_set_num_altmodes(con->partner, num_partner_am); + typec_partner_set_num_altmodes(con->partner, num_partner_am); ucsi_altmode_update_active(con); return 0; + } else { + typec_partner_set_num_altmodes(con->partner, 0); } =20 return ret; @@ -1138,7 +1139,7 @@ static int ucsi_check_connection(struct ucsi_connecto= r *con) static int ucsi_check_cable(struct ucsi_connector *con) { u64 command; - int ret; + int ret, num_plug_am; =20 if (con->cable) return 0; @@ -1172,6 +1173,13 @@ static int ucsi_check_cable(struct ucsi_connector *c= on) return ret; } =20 + if (con->plug_altmode[0]) { + num_plug_am =3D ucsi_get_num_altmode(con->plug_altmode); + typec_plug_set_num_altmodes(con->plug, num_plug_am); + } else { + typec_plug_set_num_altmodes(con->plug, 0); + } + return 0; } =20 --=20 2.45.0.118.g7fe29c98d7-goog