From patchwork Fri Apr 19 21:16:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13636766 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 B660F37719 for ; Fri, 19 Apr 2024 21:17:24 +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=1713561446; cv=none; b=O+s1kK2KLB1vz06tWs8wZ5nbNX8jvNjIRYzyoxW0hYGOkk9H+I0yvw3NiViVI9jdwBrudEomeLOqdA8viw4/Hb65fYn+Ug3zrSQgNLag34pbRgb9zXcLh0TzePwGUcm9mtECKGAmXn6jYwdCetOjYP8WYnI0GKLxX0HO9BWcXjQ= 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.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="Mjhy+zI4" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-618596c23b4so45412747b3.0 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=kJlhBvYjOxBDO3JpHk0eP53AZNjBid4gufdvBken1C8dKXrioBywvSTnIaLMlyQH4M bSrRcnsfgLcs+0vvjjSt7TE89kEFTBjiiuD7B3TkbBRs+zvp9XJmNdHVs9wuUqdjmZ6b Re3GK0cp7FfFxgUnQ1NvZyva8nOeUIagfJUu9rVDdN+qJg2Cny9/3UrKHaxI5k3Lqm1y eWX7ff8AFS35621rh91sCe87LkicHHGYNHRvci/k0q6C/b4Twc9D99PsDXGPG3Gv12YL 3KfSsSiiykZsILgOKpw2LHgza3bhORjON3lOW3OuRwLv1YRoVJEzw0fK47KmxUgg1z3i qcHg== X-Forwarded-Encrypted: i=1; AJvYcCXazan+8bDszncmeDg3O4XjdVVHM/gNrMlINoHqnbaf8XznnsYyBsJ349bgjh/09FN1ValvX0eqWu5t5GCBOfcpkhs1FLehaOA5 X-Gm-Message-State: AOJu0YwJuG8dU1bV1yk+uN1k7LG7ia1LzKY2DMg21+6MOAAvs8ctWLV6 imInsk+irPp1Mok9qwa7LL+s/bJ5+thw4gm7OcYjpIZC/tfYAhiPI0/QpbXmYorlm0dz/vMAT+A CfQ== 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-usb@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 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); } static inline void From patchwork Fri Apr 19 21:16:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13636767 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 B60E813CAB4 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-61ae9ff0322so51179187b3.3 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=EK2LEt2Ol4afC4wuC0h07ZkVVofd2Aouirz64MG173Gy51hdXqvafubu1N7q4DQGoU FeqhU1vid76DZaqEpjgx1c7PZ7CaMNe1GmeJ8X0tewCM21QQG0gpLLfoLhe5xPt54vyK Vu40WoTXz9Gh7csoNsGfTwmH38cqCEoF1CF2qXJDRaTx0M1Tv8Yz+frBPH1Kskn1dRb0 EuOq6ERNhdOmrZvR545f0Phidn10RAc53am0dcowI71OKy/5oTY1yHhsLQcrv6C2BGpo HBHMckBLnrDIdVerE7r/R8YapefJ3RaS/7hwFZ2WW6fBSQTcSETXP7nDNQkITKyZzSb1 de5Q== X-Forwarded-Encrypted: i=1; AJvYcCXbi90MyrKxoETf5czXrS+KdMH/YCR1ukTQb2O9TO5MMQsjqYu2twhsfJv43qIxeJomaGhlxPofFdQKdp4zu9IcRIdSGVx/R5lN X-Gm-Message-State: AOJu0YyN2MM9xP4RdIStdlalACpjyw3pkKAlEbAx8amlN/PSW/lD01XD WNaj6BnGEroTFXmhlZ5g7bDu+G7w0xBn84CNhjqZ+ZwR9eW8Pj5omGL3PVvA8SEJgi1DZnyzg7t tRQ== 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-usb@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 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: Heikki Krogerus Reviewed-by: Benson Leung --- 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/altmodes/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 = alt; alt->desc = "DisplayPort"; - alt->ops = &dp_altmode_ops; + typec_altmode_set_ops(alt, &dp_altmode_ops); if (plug) { plug->desc = "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_groups[] = { NULL }; +/** + * 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 alternate + * mode can be activated. + */ +void typec_altmode_set_ops(struct typec_altmode *adev, + const struct typec_altmode_ops *ops) +{ + adev->ops = 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; } - alt->ops = ops; + typec_altmode_set_ops(alt, ops); typec_altmode_set_drvdata(alt, drvdata); altmodes[index] = 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 = con; dp->alt = alt; - alt->ops = &ucsi_displayport_ops; + typec_altmode_set_ops(alt, &ucsi_displayport_ops); typec_altmode_set_drvdata(alt, dp); 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_altmode *alt); void typec_altmode_update_active(struct typec_altmode *alt, bool active); +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, From patchwork Fri Apr 19 21:16:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13636768 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 95CAB7FBDA 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-6167463c60cso28859197b3.1 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=ZD4xUq1MV0pR/EK0bCgKqPQdD8lvfRBn2pnGdB9eeRFXd3XWpY/Cgwjg9FkjylNP2f lOjmendSbQ4mWDuUk6SmJ34iD5NnJsIzNOSuICndQCJt0rHd4pJeE8c3qFlAiGRAEB+I SbPxqNK6SrXa2slWtHlvTVQPaTiHjjxdFptheYaigtTaQKXOzaxnmQlN30TcyYnEHNS5 hPaN2Irvus3IihPkEHl1A7EPAgG346qY42JpNOb/3Urq42e271zUPT/Zy+HpPkE5pfnJ QGvCci0PmRzP8ArS5mHR1XH9CWoTl/wlq7Hsnm0UhDIWNe+NgWbr6lMS4eAEy5OpWJvZ hmyw== X-Forwarded-Encrypted: i=1; AJvYcCXU0n+o4clg6RxqGTydoKKqt8fcq+Fd+/M9aF0d6fSj1mTR/j+M3lEPpTrJN1Gy+8kO2ub3DpkLWV+/O6wzCEeMWNhu28D/khQo X-Gm-Message-State: AOJu0YxFifSR1RH8xR/9Rpw91NB23FVEuRA1zkvO2oOUzLRQ0k3jMCo8 0PrSKFl1sGpcz/we8MeEYo1LRCi7Cz4XP5gBGnUX3MEC3hYGGGi83Jb7rrsozw3rcOAqzostC9c Piw== 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-usb@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 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: Heikki Krogerus Reviewed-by: Benson Leung --- 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_connector *con) con->rdo = 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) } 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); out_unlock: mutex_unlock(&con->lock); From patchwork Fri Apr 19 21:16:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13636769 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 3AE8D13D284 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-de46620afd7so4305528276.0 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=vOM14ZhmUsn37QUaFxDO2S4AI4G1TGQM/5XhieuKefC7mUz2K25AWF9s3oUuYekFk7 IAH/ZL6Kpryim5rtp90XKhrQ+FMRIRhI8wJoBAuAQjI8ACObr4zKG2WjQAgvCOxAc8j3 pNFm4lmwnDi3Tz7PFnvlG4pRlpo8W/XYmWGIKoWPY9NxLzN0CVIyxoVshKvlge2CP1JN Y9qO8YQj8WveND+NECMU0bCby1V92TmpqiHSZvOOfxGkXqNJyOx63oHNxvss6R0rYPeW 34bYW9H0Zh2EHe119bS8LSk+tkzxCJ/iIhhYdy1A0hPAVjr8xB8C/zmBVC+dXlugMXRK jpRA== X-Forwarded-Encrypted: i=1; AJvYcCVu1jI3nuvuHKQ5RYss4b9ElY3pHlyrctSBb+3ayPXjj9AqvWUR6t50rn0tRmTBZn42+BnuyCpxsasWJN139Me6KciSU3ohYfYR X-Gm-Message-State: AOJu0YyH4q7y6Gpze8ad0YNlQ73luEo7aPg26GHCqxUdHj02cFHim3y1 Ni32X0UBilM+nKc2KDQSR6BzxGBVVcqg9Vzqe9C/0yEpTwJx6dabwzIKXsokkIcwcqLML44Y68C Aeg== 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-usb@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 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: Heikki Krogerus Reviewed-by: Benson Leung --- 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 = 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); } return ret; @@ -1138,7 +1139,7 @@ static int ucsi_check_connection(struct ucsi_connector *con) static int ucsi_check_cable(struct ucsi_connector *con) { u64 command; - int ret; + int ret, num_plug_am; if (con->cable) return 0; @@ -1172,6 +1173,13 @@ static int ucsi_check_cable(struct ucsi_connector *con) return ret; } + if (con->plug_altmode[0]) { + num_plug_am = 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; }