From nobody Fri Feb 13 19:27:54 2026 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 AD8D5376F1 for ; Fri, 19 Apr 2024 21:17:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713561446; cv=none; b=joKkYhUNcp6uUg6JTqG9Z4gA8iGwnMDR8dr2htcNvDrX0KIzrK5BFzCGm+Z4Cw+tbOXkU+hlXX9Ip3aVpO7G/cQJbFfD5VxCf9S0MNKmfddHSvYPYFXqvch8FE/Ty/HKwrom+qooLZe02kggFaRWntPiMoK/v9QxDOoeobbGexc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713561446; c=relaxed/simple; bh=mDPHK69wYhyI1FfUABhwE1NgNhFXTJrMPiHHx9d6gvg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ifbo2D/5rbR0b8vGHngMb7F7Vkm6NmwSRF6K0lmMfu9btXhr6jOVRo0m4PYa4Ea1knwdFLRR2OnzEQWJXKp+9bAp79dJC4KKhSiXNZKhzM0GMR+iIbNFHZgOnHWOWj2aCb7TvfgzU5S9Gkb5jMw6XDKwwKp9heWYw8CBRBCuiw8= 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=Mjhy+zI4; arc=none smtp.client-ip=209.85.128.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="Mjhy+zI4" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6150e36ca0dso44186537b3.1 for ; Fri, 19 Apr 2024 14:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713561444; x=1714166244; 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=yBGw6IRcjqsdbe4TcZZGUlH3L2LlDwYUaWDl/kHQI0E=; b=Mjhy+zI4n+5UHQVACxUUQEfizihQpF8CIH5v6Yp7TqdsNItAinR81bXl2SKwuh6AAS ahsKzxJjCQjk5OVd+lLs1fS85OL8Wet+C8QVfZ850H/29ZmhQOMDo9mjZJclezF/P4ZJ 76VOgZtA4KgUV5OtU31YIySuD2ShlkWB5cZTK9Z3Q0vKabxehBudAkIqy42IAYU9sNzf Yo/AMNnh5hwCwwV8LUe3ag//Hwmw5etuKEeaZIy50A9OgqkTukvx3CHCPPqs+miHaaHL 88kbHDqatNcqVJgIcrv7CGXkdh9/y8O6Ws1h0XoJxYyLgDa/vdmK7fwgFKhFX5xKK09G 3qUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713561444; x=1714166244; 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=yBGw6IRcjqsdbe4TcZZGUlH3L2LlDwYUaWDl/kHQI0E=; b=CRpGL0NQugX04kHIja7Vewy1WayMIlKIl7OkPgM8gok/EFT3nCbQcRQzCkwPpnoSGm +hmn+duveCDkEUj3buykbg8cSOHTZUQdwc9Y3HEuAcz5wP9flNBMn+MhI+IU6pE4edEJ ZwHy0v0GnwllIrrQx7qgIfkSzMVBSKT82c9K8xFdNkfLP1NLxVcCfd/RWg1PYVdJqMb4 EJsFO7Q0ZYPkh+SkRwgt7tKd3V9Km+BySz3wIxrP+lYg3McNwpbvdl6j1AB6bSShshm6 avzl2V5o2g0p3uKLCQJn7/0F5Mk3v1P3G7Y/wnjn2qbd2CqeHWC0a1tTTveblswJlWZU 3JAA== X-Forwarded-Encrypted: i=1; AJvYcCUWirVSmZYuxwfChPR6UvaMwNhFrAN18WpUTR6lj64WjhjwDWTa84JJ41/lF4Ste+DbYrxlAzL2EuAUQ/Y/TfWBm7CmXyhHlmkJ5ykD X-Gm-Message-State: AOJu0Yw6P4i/H4ngjtXJozm+EGBFbLRKASEoenwxB/EUS/ajD5glTUEc JlIkA8e4rHbdINLkbg0wIwzMkCayyc3kOARt9oTnk3LlEcAPfb+8YyrsJRjIj/LTcZ7CSrRvYFQ wmw== X-Google-Smtp-Source: AGHT+IHa/iUoYwwQNUd/ge6xGKK/Ez6VGJcdqFLzOtFRhJjk1L3/bnWCMW/ccXo73fFLE030j4quwTpOTK0= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a0d:dac3:0:b0:61b:4d3:2dd6 with SMTP id c186-20020a0ddac3000000b0061b04d32dd6mr503421ywe.6.1713561443742; Fri, 19 Apr 2024 14:17:23 -0700 (PDT) Date: Fri, 19 Apr 2024 21:16:47 +0000 In-Reply-To: <20240419211650.2657096-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: <20240419211650.2657096-1-jthies@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240419211650.2657096-2-jthies@google.com> Subject: [PATCH v1 1/4] usb: typec: ucsi: Fix null deref 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Abhishek Pandit-Subedi ucsi_register_altmode checks IS_ERR on returned pointer and treats NULL as valid. This results in a null deref when trace_ucsi_register_altmode is called. Signed-off-by: Abhishek Pandit-Subedi --- 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..c663dce0659ee 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 ERR_PTR(-EOPNOTSUPP); } =20 static inline void --=20 2.44.0.769.g3c40516874-goog From nobody Fri Feb 13 19:27:54 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 9055513C9D4 for ; Fri, 19 Apr 2024 21:17:28 +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=1713561450; cv=none; b=U9MES1EY0bt690yYjsBmaYybOIHPpHooJE4Lv2uwUnXY3Uwn0hOABq5bkatFu+y9t3052KJXZHGSce2A3r3zdfaEdrBqyCDYIa72Eu5CeVnoaiBDz07tvKudqM0xsfVVWFzQIU6bLEUf6LPgFs+YLRJ8OmPOMgv2/Ms7083E9Kw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713561450; c=relaxed/simple; bh=UxgWmlbHQ6FE6Tfsw0c5bRaypsK1JoE39PHU5jzon+o=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=iZyW3YklvGE/bTj0R5suWV9m/bBohVpJvxtebgxezT6T18ALcDVeaMj7Mn/EVTsOudrd87cT2rJX49ztlt1DYnW3u7bJuiGJwwBevUqklIi12ZENtL67iGx2id1tDu4XkYds4xGQ1aoGzOfMFxQdBqYRiQxfPjDQZVVqlLxSsE4= 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=naLiCgdH; 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="naLiCgdH" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61b13ce3daaso56258157b3.0 for ; Fri, 19 Apr 2024 14:17:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713561448; x=1714166248; 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=pl1Tmr3OX/XqnrUzR2D4fjohE3sf1zx4jH0hAbozhaQ=; b=naLiCgdHTRkNVPBoI2K175Bep+tbwkcZDOYdEvzEt95tu7zCXwnXf9kWsdYPPMwEhp 3YdMagFrPu2+XiEhNsviZAzwpdd1ymoOvOripxppKcTwS7dQvmE5nqiUUujGbVoLDCiB uj/UUz5GK/6sjmHlxSkdy1ehVezcp9jXdiGkopfdgAjVn3RyJ8/N3MD/vbUO00wZe7GK 1KOSntnvev5KZb3ZIXURd6TIII/UY4WR3sTbRbHCo7KXC2c0WNj/Vc2lWZNf3fJvwvwz mx2pvx7m6NgNh/80rbPYWol+4zqgAjITLRKuATHgyKl5wZLjQrghWzRuqTFZLdCpP0SI u2Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713561448; x=1714166248; 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=pl1Tmr3OX/XqnrUzR2D4fjohE3sf1zx4jH0hAbozhaQ=; b=aRif4FEsWBc6KZmr2DyVSxCL1qHQpFx2Ur+A7pDNtCfr+adWD+PNHWTOp99yE1QKzm Xzm1SlrAGuJp5I/hKep++NbRegWGlNXqhuezsuwWLsSGRUUJCK34dFOpbgFuHdA6EbjV Z50sh8E9UJ07v4hVsBM4UphNbpD3jCouCGLhRQDBwyhEDCA2ztnXNzU+c6jon8W+BN/9 6ZBT47N2JOcZ0bkvKf9EvX7xqegojii33fcMHKqd5lj5qgk1YzHRerd86JKKjQC+zNyk vef1MxTic5psFrtz2iVr9GCkoVvhzTVj052cXNSMTxDCfJ60sqrHu58FX65JAhDSkLEq KSKw== X-Forwarded-Encrypted: i=1; AJvYcCU1ZD///5pYKBiopxKi3egmozL2p9Na+PKotI2o8rG1qNiztWINxpc3Dk64IthAXQcD8vy0CCyWwpl7oEg0eA3kWQKx6yV//IuQy+k7 X-Gm-Message-State: AOJu0YwqVCqkonsfhHSx6wBQfpbqPpw37NF2BspS3NVezi2x6H8OAllH JV7LsnzM9CAUiaa4GPc59G+neKQLMG9Oj7yutoEuzEQuRbPtnymbQgicZq7iLJ5f1tjS4/T4NeJ ENg== X-Google-Smtp-Source: AGHT+IEQ+b9tI3DwmZkiOYMQVTS5x1KoXW9+8EbyfwH0+BAWFReOfrjeVwdV4P8KFrKDlAPmSCUWfx78JE8= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a81:4e04:0:b0:618:92c6:64b1 with SMTP id c4-20020a814e04000000b0061892c664b1mr764547ywb.3.1713561447800; Fri, 19 Apr 2024 14:17:27 -0700 (PDT) Date: Fri, 19 Apr 2024 21:16:48 +0000 In-Reply-To: <20240419211650.2657096-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: <20240419211650.2657096-1-jthies@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240419211650.2657096-3-jthies@google.com> Subject: [PATCH v1 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 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. Signed-off-by: Abhishek Pandit-Subedi Reviewed-by: Benson Leung Reviewed-by: Heikki Krogerus --- 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.44.0.769.g3c40516874-goog From nobody Fri Feb 13 19:27:54 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 D820983A0B for ; Fri, 19 Apr 2024 21:17:35 +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=1713561457; cv=none; b=uScRZN08AiCfIbHZFngUdY/WsYsxowh0yJSxaWEnNTyAZdyQ2zMe4Fn1ROHVaN8Du8bctdJGbb6uEfx6gLkmJXoSrJVv54j0JSVfF9g5AQbPhdcvcYVol+66jQ7su68H50Cs63G7SaSBnXzI/3yAdiQR3Fq4WMS8LJEkRQXR0Uk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713561457; c=relaxed/simple; bh=P0P2LNQRmDYCC/aEgFub9LeFI6oVcHO/6OlaFAuYLpc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qc6zIcnz2pIWrLFmarmIrzQT8W9QWtIQSu3e5e//rS3MurH5AyM0oG0SSeNKKfSTulByBFoLs5yh7kQ2q9tEFSM6pEiRdvUIJ0mssIK6h/85s4KL+gU0HyoYlMQtXpVACSIAAYqKNDl4T1T7Bk7poGXDFtWCFpHMz5YlrTqBPD0= 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=sHjgkPNT; 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="sHjgkPNT" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61b36187e6bso12891027b3.0 for ; Fri, 19 Apr 2024 14:17:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713561455; x=1714166255; 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=g+Cg+N/7bN9qoM+g/2vlu/SplO5LfLDY99wfjzIBp0k=; b=sHjgkPNTFSThpZGRNlrZv7HSNMBZWV9nErVh3B/UFixB1yfiiXryY8EbpAPNgqM/uL HO6FDxRPrXufZQ727IkEB/zjIU+PdYcnagxuXrufZQsahfRex8cAqN69qCoQw1zbq/64 kRIco2ZdCXtFrOgvoSI5UpHwJP7acKEIc+e9eoWY1ESp5Gm2CfSUEp4Lx/mVZH94m52/ dkZ3on5QC3qxBpIZydiLR2aOndLUV0ls8hyysrQPG0v6sjKo9ADAme/xzF78gqKbIXmE QwKfP6oB1N3owMuju1v4Qe2Kxi/SqCsFN3GrYgNu4+8F+9S00n0c+uYReueCbLDIwTWV sHBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713561455; x=1714166255; 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=g+Cg+N/7bN9qoM+g/2vlu/SplO5LfLDY99wfjzIBp0k=; b=VENk223IPPzNvW03zCWsLVWZyc5O+bwyVkco8hDQQaPZYiM0s8wlHS11SJmNvyAxpk URTDxfKaRTK2yQIxeyhif8lXpRdBncX5pWQpAnYX2SdXwoNZIhIHPI3t7Kb70IebtBMN cAPovzqeCv2aomzxeoPUeDCq8alhnY0BsaJLCZf/xJYkKZ9qCgcZND0zL/kpCKG21wug /KuT8IgvqSd98vYkqFjO4ddtedazbZD5zqb40xhixq4JO7L4reQ+PZVnJbdpZqexXbJm Zrw6Qr759usJNO68V9IzBuFgk6ed7p2Tdy4x6CHAy3nPPzQrVYR83jT0HvNIv8PsisLn slBg== X-Forwarded-Encrypted: i=1; AJvYcCWOilOajRvjvpSDzoGdkLtabA2kHH65X4CYdFYd2y7sOsKIGmKoiB02keEtFoqiRdwVgSE/Ii1jg+EUK08v52FFdrLh8rmgaX4aXIqN X-Gm-Message-State: AOJu0YxTV8FxAMWgCwna782Xbm7Lxm9TQTXfbaQlq48hBx2a3gDRFCAl I2zZ6seRJLxclyk041LXgQe6gA8Qf/ks8SkitvM5U6hN3InNsd+xz7BKIAhB8fzkuORMPcG74EH ntg== X-Google-Smtp-Source: AGHT+IEvG80FpBSTMrUyNa+jaRsdc9P1PtKc0Ymjy1JxePfxLENwQ1kn1BBI/itnoi5SmdtePMi9pOy1jYo= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a81:6e57:0:b0:61a:d420:3b57 with SMTP id j84-20020a816e57000000b0061ad4203b57mr873351ywc.0.1713561454867; Fri, 19 Apr 2024 14:17:34 -0700 (PDT) Date: Fri, 19 Apr 2024 21:16:49 +0000 In-Reply-To: <20240419211650.2657096-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: <20240419211650.2657096-1-jthies@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240419211650.2657096-4-jthies@google.com> Subject: [PATCH v1 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 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. Signed-off-by: Jameson Thies Reviewed-by: Benson Leung Reviewed-by: Heikki Krogerus --- 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 b8d56a443531f..cd4c3b7a5d989 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.44.0.769.g3c40516874-goog From nobody Fri Feb 13 19:27:54 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 26FA313C91F for ; Fri, 19 Apr 2024 21:17:40 +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=1713561461; cv=none; b=pzEcfKI7DpFTlVc/AF9yB8Dp6j/XZKsSoubk9agjqbPZSdHT0E0spx8ayF1gJ9dD6PoBAHFQlKtKt3QM6wIz9s5Z335ZTk/tAiEcPho/YbgspFrwPTXwJedXQI7DuI+sDP14daZLz/pOGdMyeVeqXJOTZT5Dd4bdRr8uUP+i3Gk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713561461; c=relaxed/simple; bh=fKUL0oJVWhyKPyuWrBggFRR7WK6liB65Z5EkXKyHftw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=o77xe1RKTXjFQ4CTS/uLgKMwAi+TRqACgHH0TPhxQESr5Wl2phJVJQC5WnumFrv+rQaVowYv25giBlC1oJ6qxMyXENTTW8YZ9y3nYeIVMNgfSkqQCXmCHITf8RqYbmYciMwWMUuOjKv7LJ+X2X9lu1b9mcgsMEwlECMWLrHNw70= 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=DUNdSrUp; 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="DUNdSrUp" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-ddaf2f115f2so4113966276.3 for ; Fri, 19 Apr 2024 14:17:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713561459; x=1714166259; 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=S0xPvMdWQfhMydIZIXU8mYIUBlrWjYZf7B5Lw0rva50=; b=DUNdSrUpu+CxyiD3iIHfZ7mgXpFDpyJGvXy0bSwXyYLAnXZ79FWKVji+Tzdf+J/zLl a61PjEqt1HLuNQKr0Eo/0kFlcHEL73I+JcF7f6LxA1fPZbD1T5H5K0BTOzTSwHf/KcNw I9XmgMSAgxkinyiAJzRyFZtpBAL95xVciWvEBe7VBU20HBWkLkKikDjhXqFyG7gyc5bb 0ggZX0Y4fPsJZWHHYzqOajT58iccyTZl0UEts5kT0BRjNX29dIo6zLKq3djBrzpD2AKs 8b7vEvbm5qYpW28p43l6q8xzXYPIBJPCnO82gHxohLJoe0sZjdlldv8a0c8hFPrGokEY 54zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713561459; x=1714166259; 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=S0xPvMdWQfhMydIZIXU8mYIUBlrWjYZf7B5Lw0rva50=; b=sW58ho+QMY9dfrOMdJkstZS3PrKftaj39KXrkn5wINFMlUgzp28erGezZSdU4a3j7y 3cZeo/fjFlqM0irgSifm7C4j7LLYR/7jHQN8EkWRq1ayz3UZy98xMGRLV3jubcXqjEsf +lT1ZL1Nn+4wpgj5xcUK6lkgRwlB4U6WCkM0iG4LCs9MvrkG7IqeM3FtZ14wIgmd571o CkU+0svJTUqPlwAT5a28/aAzyg3Xg+jiXugjVdGGF1AmZ2rNMhs1AYhrgoefD2fk0HIz RSiQBmVkhXzK4JYr48aC0j3GmN/ehY8WSH3tU1g42lEEBScU18imc7rpMAhGyPdrcPe6 17OA== X-Forwarded-Encrypted: i=1; AJvYcCXffwwKDnlv6fcs11DEvCgl3jejwwqoo1Xa0I7uwayDeyQCmpj3P4wo5iRfETLg+BC5GlvaT18GWMC7+RgDI98ew0kOicccnc9FmS6S X-Gm-Message-State: AOJu0Yx0saD+ktfen/SZ+HOxeASAeDT1KDaHEIYwYAwZhurs8wzfmoeN Oxx0SRlz0G1jzN7GYHVVu2NZ5xNkj8CbG2HOw+fp/oDr8dLDPImXNZS+G9D+KXOgAMtwZLI0vWm WNA== X-Google-Smtp-Source: AGHT+IEMwBE9YOgE81l22lVApUq3I32FekRt1YSUsjnTNhNb9RBOl882ihIkSmf8/uWelKVnIozwby1e6t4= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:6902:120b:b0:de4:c681:ca96 with SMTP id s11-20020a056902120b00b00de4c681ca96mr249811ybu.2.1713561459255; Fri, 19 Apr 2024 14:17:39 -0700 (PDT) Date: Fri, 19 Apr 2024 21:16:50 +0000 In-Reply-To: <20240419211650.2657096-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: <20240419211650.2657096-1-jthies@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240419211650.2657096-5-jthies@google.com> Subject: [PATCH v1 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 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. Signed-off-by: Jameson Thies Reviewed-by: Benson Leung Reviewed-by: Heikki Krogerus --- 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 cd4c3b7a5d989..ea76d42fd1504 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.44.0.769.g3c40516874-goog