From nobody Wed Dec 17 21:01:17 2025 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 238D1FC11 for ; Fri, 3 May 2024 00:39:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714696784; cv=none; b=ZkMO/mbv02TGEF8rM5HsJo9liW8RFqV0ptPAyPDLM4hWL3fG9kFqyylehrgsRao7PWMFEwaZ9AfKwVWNsSSWbrOVaABH2rNrbim+8Du/HIhj+L8rVncDYtcEGzVvB9VIy0PG4ixShCoZ1IN84kRPiJb/w40z/8POa+qSwSo1Lrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714696784; c=relaxed/simple; bh=UP93LeOYyXTB+HImKxRgh7AV1DkTaG5cFD8ox7MDsiQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MpBr1/Cw/haTHOAaYhh9o6iNS788YKOvdLCo/wQbNQiCFRiy/Vb8+Gadk9FLx/awcnJDnj/I8bq7mbkygVm1n/xLI8LwiY38EEUeRN6+Wka6Ad1HuDmDvrFTZvy+6xAeGi9GTTvymsc31ZJPLE9LHSsO/Lrkigjo3ZjR6s8K4tA= 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=JKheCkuq; arc=none smtp.client-ip=209.85.219.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="JKheCkuq" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-de60321ce6cso8559465276.1 for ; Thu, 02 May 2024 17:39:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714696782; x=1715301582; 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=y7QwxP/IR8IteTIhBkWFiOVh6L2OPrMA6wzDacMquRE=; b=JKheCkuqmzYFl1QYiE6JECplSgRWMunYiDmQtviLllTN8XRBZxBs+Won/AWf92PI3x MdILQ5EaVyYePNfSioCzUGzUA5qouPnoHVx2Wdc4Mkt6mrSRup2hOjz0Z0fAI53o010F TGbOZvv8IWcNMF43veWAzAlr+/b4HN0adWXu5VUCUjgVvBaaQp3Z31o75bpiATL5BSPO vQ4Oi5RoYRxxC2ppiVbCYx9sRp8/MaICnV8ZFx5s4TG0+/0RQ7mh3nsdza5S/e3GIwJc G1rbB9534TTN0asHBMeSjNwXgsPKI5wk38sLEGfOp0o6dxB1sqgVUTSY6qHt5b7XmWyF 7IYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714696782; x=1715301582; 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=y7QwxP/IR8IteTIhBkWFiOVh6L2OPrMA6wzDacMquRE=; b=mZOISfqMbEuTwbXySiwqCF+CFW/qcf/tgjFCk6lVH7Fn+iBvhHUKcUlr445zQNN/lz cFG/xmTeDUN+dtaOSkFXVPh7T/ohuLSGiLUo7V5zuCEkVq4INP1Kx/P6usvv5FNDznwX 2r1NEjCxAKF/Kluqim3jX6p0DiC6e/6z8OsB73VhBuKHDFFkNrI+pwYiQhtFusFEAJ1R 1t9EpgHE7m7iOaL3QHp9XkUTtaIWeLW+MIYHzvLEozSXGsamz+OlVKLoOhCDP5W7ptd0 RpQSbfbk+I8X+Qoamsw/oR89wwMiY01g6vlwEvYvVYan6ZtrtslzIVHetb/qAzYTMJ0p RoPA== X-Forwarded-Encrypted: i=1; AJvYcCU4fEmI3LDE+KCgOwAktFRN+I1D4CXPX6/mP3y8SYEdL8raWkn9WEvNkVtRfpAW8ocnI7/Dy6v+pwDS0rnleRcpj0bLqOb5kwHg6rQx X-Gm-Message-State: AOJu0YwheUL62fIyKZJwQ0my/lNdoFiUxQt+dH+P2sL8385zd+7/TuQN IKPi2XU9QrB27XpJg2HHFQzvXCcOifgQ66R3IlBTfvqcnyWrVg3juYWzt31n3vwnMcWGHQ9Ty01 Oag== X-Google-Smtp-Source: AGHT+IGA7rE3BAM0KG2lZo/Ms/y2c4C3BtZJwhhhC+5ZNSIrGkbjl7DC+rrug/J1iX6eTsVMQyasB7za2KM= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:6902:2b89:b0:de5:2325:72dc with SMTP id fj9-20020a0569022b8900b00de5232572dcmr426447ybb.5.1714696782126; Thu, 02 May 2024 17:39:42 -0700 (PDT) Date: Fri, 3 May 2024 00:39:17 +0000 In-Reply-To: <20240503003920.1482447-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: <20240503003920.1482447-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240503003920.1482447-2-jthies@google.com> Subject: [PATCH v3 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 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. When CONFIG_TYPEC_DP_ALTMODE is not enabled ucsi_register_displayport returns NULL which causese 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: Jameson Thies Signed-off-by: Abhishek Pandit-Subedi Reviewed-by tag: Reviewed-by: Benson Leung Reviewed-by: Heikki Krogerus --- Changes in V3: - Returns typec_port_register_altmode call from ucsi_register_displayport when CONFIG_TYPEC_DP_ALTMODE is not enabled. 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.rc1.225.g2a3ae87e7f-goog From nobody Wed Dec 17 21:01:17 2025 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 9C33215E9B for ; Fri, 3 May 2024 00:39: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=1714696789; cv=none; b=ZXHWVNxnorKHBSiWxvrxY8oEKbs0XKCdGeBHGnGxlTF8bxF8Ln4B+TNO/MaRMyKyWlQqioiajgOaBRh1fSStvQZv65MJ/apWKY8qSI3E8vJ9BGIv7C5Q+yaMb8KUBkJ7kcxtEUmUdvrTqwWfMMShx8bDs2P0/VonVgYbk2dN5Z4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714696789; c=relaxed/simple; bh=1W6WfWN99WG/pjCYyMD+X7XuHDDI4azbE7UAfj/7jS8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LIidFfxTzLmqOhuabPSMukvyUp6tFdwdIAX3qmZmsbqId7nWJuYsa+vLFK3UsoPkY8asQ9bWWz7mmysJC9/nd2HtcpfGDvCsf9hjsy1QiGfyy/0VXO1BoWrZPwMIs92JYxrsaTEw1lS32GiaQI403N/xDYiFoul16dw1L8Uqmvc= 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=yA3B7DrP; 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="yA3B7DrP" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61bef0accddso68843347b3.0 for ; Thu, 02 May 2024 17:39:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714696786; x=1715301586; 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=Ev3cYq8jpdJihaDvVJt0iSYbqkUt898jtR/GbVOU2w0=; b=yA3B7DrPU/ieKZ2wOxG9sEQWe0ugOTXMleihyGLewgSyLPBbJXDnUMm4VHzN/6FLvW cC6Pz2vn4oBiK9EsngRZS8q+NeupvXf0ckcOV7ILLCVD4bXVNzO+QwiRqPpw2+WfXmyc px5bNxjpw892MuAFC0Rsrqo2DSEBEhHUHrvDshhMqFutGREbG6CRQVv+wrzotDS0Zevv a2BJMfFTXtsXORwkq1WUYGPKK88QJfvVZHwSLH+B2g8SazPbUMeuDZG3Cl2Se8rrjiSL hk9oQ5mtZ8rcwx5nUz+/NN9kbQ/Fhe+L569wbMp2dnRDCJwMQkZiiowBQpEaDmc7gRoN A48w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714696786; x=1715301586; 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=Ev3cYq8jpdJihaDvVJt0iSYbqkUt898jtR/GbVOU2w0=; b=byoID6nPuJ+jAWpG/pg7wtFtTEjrMq7dW4MvCZ4MDN11AYe7MhrFrh/X9g9zzhc/WZ qLv3l0rUVhqO4MhyZQXk0JsxB8YWIMiF9Kbc/ZZrjPs/vpmsnR9QgKpc4/xCzuTdarNW dyXDLHNUjjMj8jnJOMqrw/oNGK/57PgZ3865Uy6Cxn3lEfHcl5VlVze38oL263DJ3nIj W7SrcYFs8gIJ7ESPRJMEYYLEgtRaLFlt+ZsROlgRR1hsjfSMJ4VZADGhLV+sPZUwelC7 Dh7dO5Tu27W+nehp0ww9s/A9t9il0+NftvVXelEIx3kiNEuE2FPh93/KJiKC4T8kZ1kb RVzQ== X-Forwarded-Encrypted: i=1; AJvYcCXr65zT4RfCzhmKsBZYygw26nVdFsCJa5AtY0C14x9lpUCUrwB1qLhaojJKrWZB79H1gJyCzBM6CZRgNohvv8u7bxXnE4eKCyQ0HfQB X-Gm-Message-State: AOJu0YyNYlBDLidEBGWiWYk8E37Qy/Br4JmJkuev538X+IfCER7k49JF 8+/IQYIED+DN4xLp8DfBu/Dh+l4NrRl1VkpcA1QL2AOHzo6UdjR3J1X1JzX3pyaqHPlozvN/a9Z ifg== X-Google-Smtp-Source: AGHT+IFsDXHVBXexV+q+HUPPZ1A61NbpNAX/YNO61X1Tzqc3GZbiwPa7NnrSWuFsoBHqRKuYYgTm+BG32hw= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a25:26cc:0:b0:de4:e042:eee9 with SMTP id m195-20020a2526cc000000b00de4e042eee9mr383303ybm.6.1714696786732; Thu, 02 May 2024 17:39:46 -0700 (PDT) Date: Fri, 3 May 2024 00:39:18 +0000 In-Reply-To: <20240503003920.1482447-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: <20240503003920.1482447-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240503003920.1482447-3-jthies@google.com> Subject: [PATCH v3 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 Reviewed-by: Jameson Thies Signed-off-by: Abhishek Pandit-Subedi --- 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.rc1.225.g2a3ae87e7f-goog From nobody Wed Dec 17 21:01:17 2025 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 A782E17547 for ; Fri, 3 May 2024 00:39:50 +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=1714696792; cv=none; b=u/kjWwDaw8y5JctbZVbnmVqXCqmMHXzIWfrR/+s4UIukLkDWAgw/Jl4QOoQNbfeuxt2r4Frl9/DaHvP0k4jPv6u3NUsl30KTmivTo0yzY2aNlzPWCYGOS5zFxjYj+Qp3Q863m1h9wfemAlNcEO4r2zS2hBHN+AlRlic4mh0141E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714696792; c=relaxed/simple; bh=lPHkPZBn4jDkynyngXHEQSInVHBG5XHwELGRCRAANtY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=cHgMgZZfZqrDXCbwpaK1SIQtQWqvjyqFCXh6Br8bj3yRr2Z8RBYir9okafapjos00uq8+M2fMVJku/t2DsPeee8dW9xCctZ5BMFlBV8292e2+SfDAuQpp8j5svzDPSW3aP5XdqRk5/TYm24O67hfCzutLDjc43rmbsmpPdHTfTA= 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=tWU1ogX7; 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="tWU1ogX7" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61be23bb01aso93832087b3.2 for ; Thu, 02 May 2024 17:39:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714696790; x=1715301590; 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=FSyCNdHT07TNdA8h5B3w30HbKKc0j314DRlrHa4lbZ8=; b=tWU1ogX7s8djMPuEmSXOsGt6v9cox/ILjl6ekn0FX6yO3RLDGzmiq31L90E3DR9GCO E/nBiMIpkZWEx5P0csOFQCxRr+Ch8R39monu7nSmNBO8L0Wx5MAtlJpcEwucrkhBLXH8 W4oXrGacNA0jV4hlmz2U6DstAbsOUM3kZnTrL27kRhZw9WjKFuFRiEK+nzTTQrfHRMCi 7rgUQSeDmENkLVPasem1dwwn9hYC6oMhS72BqvsOv8ytoVHR+g/puqBFFN0mlraa2BPA SsLgwJdQnP5QMR9057iRu1/mQ9ihBmFfzrjGzvXqa4B6z0kuSAZWYqrmwgRpk4/3Dbgw KPRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714696790; x=1715301590; 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=FSyCNdHT07TNdA8h5B3w30HbKKc0j314DRlrHa4lbZ8=; b=jwe9eTYEsR4wMhWPMS0B7QDrF+uwmJM6/WdKKpSwSHkn8TDopjywM52MkMgrK4iPfu z/5gO3GONE4w/88wCBi0j7u9hTDRnFe+iw8gk44Mk6lViWfOtAZquVTFN/PDnM9TahSk LwgZys1Km4g9JYqxHxSAHUmWwnpnJR3E7lNlA2mLjaFB5VfVP9QlBmEqVDiLObpE9SIJ OC82Lsr1EcAp1vXjjA5QBpxYFLGtXa3OkrwuFeRhz2LYH6icZYtHqYrW2UhrYaLOpj2n umdwXGZOI7knlSRO+37NVt9HO3hfEutyKiHvu1+0xbTwl5VChZDeZBUZ3+d4fTUCj+s1 fbEg== X-Forwarded-Encrypted: i=1; AJvYcCWolZ93riV81RzWWdhYJfJ6OMVSBB7KjYJCydJnQ/u+qNk3lJrde2tsfYe4PL3W/sZAu4spSpC6XScGeg9jRNWVCVF8ZPJDim+PNXPo X-Gm-Message-State: AOJu0YyFkn1dS2OPQszRaaliBmNx3TLTdu3MkACuisY82Cd+XBnxLuxv WsSCo4FMiKesVzAqbKDr/1RTkU7mFyIW7yvAjDV/vxGkGeRFr3RNET4zyXEX3G2TEDXwtWBXYbj gxg== X-Google-Smtp-Source: AGHT+IFfQyw8c1TCZjy0mlb3PosEM5hsNooK3RZWKtqyZZTyYTJsB2KvxZTCCk6ZVze/j05u/Xw1etchBYU= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:6902:1146:b0:de4:77ab:5fea with SMTP id p6-20020a056902114600b00de477ab5feamr380431ybu.2.1714696789778; Thu, 02 May 2024 17:39:49 -0700 (PDT) Date: Fri, 3 May 2024 00:39:19 +0000 In-Reply-To: <20240503003920.1482447-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: <20240503003920.1482447-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240503003920.1482447-4-jthies@google.com> Subject: [PATCH v3 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 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.rc1.225.g2a3ae87e7f-goog From nobody Wed Dec 17 21:01:17 2025 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 C19411BF24 for ; Fri, 3 May 2024 00:39:53 +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=1714696796; cv=none; b=FoKjx61PSxAnRpIbwXGcZSa0FyBnSID8qfwo8nOp/4XMdLZLA4Y+4g2pkM9N8tPrCJnQgn3PAjZpq3KIcHg/7f/sSjEkehxWtBAp0dXN5V9gDEnFD2u6inYR24MK5lk+ayIN0eh1o328k6lJdTqek3WFbDKuZ1Uj/EEsO5DZDf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714696796; c=relaxed/simple; bh=qgu2ViOZOk6hT9QT2PkX/dUFnBm0XSHB9y0xx2sW4YM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FsL8Nl9hDIC93q6QFNCgmllBQjdD3TtISVRz9JQ+xDHBdz70dx3HLHdk6Kvy19jDcoWdHluTUqO74Hv3tE21bgIFWdImNC2iXtQRV1gpZu5ZjcmdCtyLfahttUTpfz7aGQ136FRbB8NCAG2i/c7P8hsef/h71XqJtoimWX8XKfk= 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=h1xL6M+D; 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="h1xL6M+D" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61be530d024so79238927b3.2 for ; Thu, 02 May 2024 17:39:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714696793; x=1715301593; 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=GHcklqlVkDgPCWtLjA6mJ8uUEpbeCPdZPZls8J1AN9k=; b=h1xL6M+DA8QIWugKiHHdt/J2FOJubjBSjEFNpwHZEbnvkxgnH9rnOrRBjQB3kYnhQU /KcfkNEBsehVD3Poug2wyH7L222UAKxUzKMQYntR2ho4ceCs5WeQHDSlxiqt/9c07pK4 3tqh6299oDBm2dYAmE8rPdLcciUkAfO2J0EhjT0PSnGie6uLqhl0L9krye/8MtZOydQr 3HJiz52Mi1b4L1t8vWY3HY7TKsqqS5AbJ2ouFWakgmNgCurfpX7Jz7nbdy5Peznstbok cwrO5GMHFX3vxOT/NAfJ5TlfVKnEIsmI5BYm+cOIo/QOCkqJVQ0gG204c3Y8h23/iT7N 8fCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714696793; x=1715301593; 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=GHcklqlVkDgPCWtLjA6mJ8uUEpbeCPdZPZls8J1AN9k=; b=C3YxSCWzQ4U+6RfrtpNGJ+Iv1WgFHuN7WZqSlcaT0z6ogj3SjR1sPtSPWSt8wJAW8k yFNVjoqlSYW2Jv2tGh7EMjNjq4gW0SyFK9PXR/34g/vDijA4hqce0w/Ge4tsEDHhOxy+ tHnxtZSqzH52W5ovbUWzeXUK+Yi8apyTeSIUGWzhoEKCZSJBqfUmbeXowFnD0FbaMOO3 mqMdD1OSzN7RQyl0uENkXwYJdocNQopjOiIU9L9Fun0XCW3K64NV6qoNXSsLToyEzASv VJ1I3F5qm0o4ChKSKtJJ2EHgoego69UatQvnxMGz9Pm73uNp8kS944BgFrTZYjf8t59V QmsA== X-Forwarded-Encrypted: i=1; AJvYcCUy7QrTwUAZvvWwNoASD66MNkEJGr17hHeS+zNUeFVccDYIxCaXXE5jzsnpBqUCeYHb/QIXquQ0u6j38dRRl+f5SdzDRQGKqzwbdweD X-Gm-Message-State: AOJu0Yw5Fd5hvm1+17g3JWZzthZzqtiYBEcOBrP/ngSSyplxbpWMSURy yqc40kisaT3VGzvEDeacEl0uq8IZdjGOlEVFk0V1aCWor+giap7arlLOs/sY+qd3Kvxwuekb/hq rKA== X-Google-Smtp-Source: AGHT+IGyhxQqfnpdZfpT1wcZoFyJw5400zJ79x/mYwXvqDLeSrFZkOdCg3BGriKoPCxDjgmRotLTtkzJ8gw= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a25:c591:0:b0:de6:1646:58b2 with SMTP id v139-20020a25c591000000b00de6164658b2mr205344ybe.13.1714696792849; Thu, 02 May 2024 17:39:52 -0700 (PDT) Date: Fri, 3 May 2024 00:39:20 +0000 In-Reply-To: <20240503003920.1482447-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: <20240503003920.1482447-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240503003920.1482447-5-jthies@google.com> Subject: [PATCH v3 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 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.rc1.225.g2a3ae87e7f-goog