From patchwork Fri May 10 20:12:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13661907 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 289CB50298 for ; Fri, 10 May 2024 20:12:52 +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=1715371975; cv=none; b=hz0LD6vMJvbb49BOCRb+up/mEB2LQsZcWJyVjg6R72XFKi0RXZi9EyGTKNPAliJ5HVMXK54UJ+RTzVIJbZ/ry3d6ZSnJwOSS7GI6nru68ohOjrUaw9xHlGF8OO9qs6JFi5LT+Wqs+Ph8MJ4oQl1/7LxATGa5619qucyxvHOS1iQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715371975; c=relaxed/simple; bh=mcFJWNvqMp4m3XJJRSjpONkZat8abDPpd8pcqX4kQEI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=DUOQO+pN/bQioPSzU/llJQhIyxYiVQyPUKWUbKOkPZnpyyuriRFj/TWxnl9smbXSvB40zBsgPUTEte+K8KVD3M1K42RPWz2mGyi5JbDoTd6AmjoHCu+nn4sqlWbDpFgL0loeyESSwR88gwaeU14j1Hm+Jl4JwhoSHzWojXZNMqg= 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=RTSsD4+/; 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="RTSsD4+/" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61bef0accddso48787327b3.0 for ; Fri, 10 May 2024 13:12:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715371972; x=1715976772; 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=TS1kguBPU3RFHeF64udttR5i+sPMcgkKBIHz9rnMR6Q=; b=RTSsD4+/bN0V7BtiMNdihEuGm4oI2YtiSB4Vi6Py+hime4vcfe/wbVlxCw6XQ9knF7 ltvRrjHgfAsNNZnz6tuWcFNh0KWGc0T8t//QyTRwnC+1/HkOWbzXVCRLIhM+zuY3UTe9 FuxeUBvqWJdK+jqSqRTntwzDLY/SavhoZHMSYG/8Cgzs9CRQcxrfzaND0f/xvY8Wq6uo lNBbQKvmgfBjVRPdMS/U+0ICF4ABny+qHzMDFLEa9GYeI6GrwHgE5eQE8bjsLnKKk3+y F84ueRmc4HJUe5rMmebv0/XwOLvThbUvmuI7DaBpOM4+YU1xXt3zk5EKyvkGDdsNhNn+ +qXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715371972; x=1715976772; 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=TS1kguBPU3RFHeF64udttR5i+sPMcgkKBIHz9rnMR6Q=; b=juzxoHPMaF5XRXhN5Pn16cQPRUvP1A52bthlDSKmPI3qjTeOrErR0kXop++0GmW62S ItI/RJ4eITuZ5wvWcz9i7Phk5bcXTMXDL62iWVNzkEu/+vAIdLn1uw3zLm/AbJ1fd3A1 tPDbzt/VUBwZgz/S0U4F3h1Qy42eI3jzrAGLx9RqtGJZEXFQV2n+en17Gblb9yx/hOBN 9bmvM5sZPFG5l3a/kbWgPVPyYFixwtZPgqimoI7r6tRmbH5gHq92Xc9wR7cbvQNaQPfP 7DZJJbzj2enV9hloD7VbSBuEiUm4u8GKhAz6lT7eCMir/vRrOXIm2XpLjfnCiZJqmZ2S mRyA== X-Forwarded-Encrypted: i=1; AJvYcCWmhY4ObQECu6Pez6Ub25vZ5nZG2BVMpQqfjyxTtL740dRDj3NGdVZSaTO8pyM1n+M58AExvdAChCULaX5jCw1PE99QGtxkIk6r X-Gm-Message-State: AOJu0YwGIL05iajFCWKYvpbO6lSko8YSW+3Baar0P8S0mnkYm6uQGGyL oPt9o8a+9EtiOOLyIT7Gx/LkKs5fYSwtpbKmsNc1YyZ3cDupA/aXj/lphNkGwOAQ+pOXXaKBqJR DVA== X-Google-Smtp-Source: AGHT+IEclD/xt7n6pEH43DFtQ8h2cGqq1loZdidf+YWl0jYdLFxBV3R8tjeJuHSlsxmK5MnXOaO2TfHw3jM= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a25:dcc9:0:b0:de1:d50:ad47 with SMTP id 3f1490d57ef6-dee4f4ac06amr827558276.13.1715371972144; Fri, 10 May 2024 13:12:52 -0700 (PDT) Date: Fri, 10 May 2024 20:12:41 +0000 In-Reply-To: <20240510201244.2968152-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: <20240510201244.2968152-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog Message-ID: <20240510201244.2968152-2-jthies@google.com> Subject: [PATCH v5 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 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: Abhishek Pandit-Subedi Signed-off-by: Jameson Thies Reviewed-by: Dmitry Baryshkov --- Changes in V5: - Fixed signed off by line order. 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); } static inline void From patchwork Fri May 10 20:12:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13661908 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 EDBCE47F73 for ; Fri, 10 May 2024 20:13:17 +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=1715371999; cv=none; b=JD4t8fYByyAqMbjx8d2BO3+D6Bdzy5xLQ2gR7hHlr9MHrifwGvlDXezWbcWgxf0xFxQZp6D8NnQ8jTQfI7ju4k8Kmtu2naVbhcRdxQyuM33cD7J5DZP0Na71PT2sPo/LSetZUjkQK9x5G1m5OCATm/zmnePDUoMtRUhwM530rL0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715371999; c=relaxed/simple; bh=xQ2rEgQNzAAGgb7mqu13QJRWKCJLNrN/kv/VNptS1jg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aBI8OqM01T1GYhxWz7JpFJe01OSKHkI92QK0jr0VDWUOGy30JYVyZqqv2vDbsfw4n03A0RQutLJR0TnOxK9lDUoo4TJSfHW1UYmhWeWMhh+d+MgJ+nCzQJslGDPKamWRTvHA7FT4lTwgMLhS1LX3tYkK6nxAEluHeu+XxjGOWGc= 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=3hc1OM+7; 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="3hc1OM+7" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-de60cd96bf3so5192048276.0 for ; Fri, 10 May 2024 13:13:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715371997; x=1715976797; 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=LSLd4C6RWuRDc53VYjutUDg53I6/Zy/8sBQNs3K9WZo=; b=3hc1OM+7SaX/wGre2uA9snQ9GWdp08+vioF0MXI96Ee1wzU0E7FNqDiEcXvMC1+cbY 5v7ddYzaxF3ep6fnzWmYGpvOrcPJuYPaV7++86nQ6V7DXonYBTuQDQgt7aPsnYCLaWIz 80QDoSMiGFOLkDtZgRUrscyfzPNBQgfnMncpNps6YXj2wnDLxj5rfBGlwNnVypkF72jl fxvkVvNUCfB+DVv3mHOU59HbPkl5+EIv8RuclWw5KyTV7QRsSpRFDZ9qLGLTGGgcKq0m GAwj6FuSBCt0fDui56SmFUTILwr/sRzvzq0fOMY6gDaG6YtJ4csORezGZQSwjSsQ+iaz NNYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715371997; x=1715976797; 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=LSLd4C6RWuRDc53VYjutUDg53I6/Zy/8sBQNs3K9WZo=; b=nEw+KntoSg6HUq9l78dTk5L0KaNAGGBMbDGcgI3spz+vMQNaqwxiSCfoqVkbT1zaKp KttI6HrYpsjikaFPx7a6tYSL45nMbm8Nhndxlid0gQ1/zr0QEBbHHqLmpoOgkutt7nda WAndP1Uiu6Ew2qei7oeuinaGX9k7QBV3gzeyXD/YCcp4bYYj+EAbTKJ0glRH7ENLr/5Q gVEig9iOB7PgPng+E7pEuUObxF/1/gv81n8fQJAD6Prk26OnKpdFFtv1drwlwR64lJqp /S0Sw3Iq78sNlra8jbXfrBQQVBcMyAD47eNv4IBp5yo8Vpc1zCnrxyvRscVjbAhFh++l lcdQ== X-Forwarded-Encrypted: i=1; AJvYcCViCNFn/6r5NafqRwYYamxL/plW3782JmbuXVpH1treJKsR6QcNHKqFi9jfjNATbooz98OD3uPkCCJmk5QXogi5W0MjvQ5/u2R+ X-Gm-Message-State: AOJu0YxoZcfx1FUfPqdrhgqjen9MEsr1T6jeaiRdWYUhs16CMG/zMYJE mlRXQkQGVSNw6rkaPaVgTEO7s7gLkGKE/MKBFv96iZRvzyUV/SNItN78QJrYodCADYdIaczfx/x LIA== X-Google-Smtp-Source: AGHT+IFD1gnGHMQrq99VY43M6Y0/j9fkY40gUznD1x217Vy48vxegLfCwAslXjkIGfB/QJUUshSewOKBjGY= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:6902:c0e:b0:dda:c4ec:7db5 with SMTP id 3f1490d57ef6-dee4e57a059mr1072074276.4.1715371997051; Fri, 10 May 2024 13:13:17 -0700 (PDT) Date: Fri, 10 May 2024 20:12:42 +0000 In-Reply-To: <20240510201244.2968152-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: <20240510201244.2968152-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog Message-ID: <20240510201244.2968152-3-jthies@google.com> Subject: [PATCH v5 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 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: Abhishek Pandit-Subedi Signed-off-by: Jameson Thies Reviewed-by: Dmitry Baryshkov --- Changes in V5: - Fixed signed off by line order. 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/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 May 10 20:12:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13661909 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 244184D595 for ; Fri, 10 May 2024 20:13:20 +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=1715372003; cv=none; b=N5zumE4+ruP0zjiLToRpck8h+zWewmNk6fFRrEXJf5GnOntSPPk9X/5RUYrMQ2X2Jl4/+kVCZv/ggrk3jcWSjau0p0mLFJnQxpPPemeo10EKIMldpeoUH/EygfzYmLfC/vMYn7RZUNBuMGnYa7MX/ex4MEUaOP0GVvu44QRVPU0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715372003; c=relaxed/simple; bh=s/KsF7KsNmNqfW9jySfUKYHz0qrPmcvkypMn9trKTyw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rrWLomnWJSjXvgpl8g8FfTQ54eNBeSCukqdyY7GE7sTNZ/g+TTomt+y5OWby+EpvXHym3Zp6pYs4gbPSABsIu4Ye3QjZ0tWtJTeIACttlLsR0ZGYBESWuGaxSeMI2tdFFuFcl/hjso+J/n26nNjjgY0Q739dVRJs0Fc0wyeF/WM= 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=iGgKgUUR; 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="iGgKgUUR" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-62230f6d44dso27105927b3.0 for ; Fri, 10 May 2024 13:13:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715372000; x=1715976800; 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=p6Gt9uHKHh1HnRu1uhOwPYNBg9fkaiXawsgjwu/g2rQ=; b=iGgKgUURDJra7q/q+qsrqQRPaFVth5wyhzcl+LVZII9B8Y0q133RrzP6/aLUpxBuBj s2bALKoKL79yWaGugkGHOqpQiGTMEH5KHa/Hfev1sghOfX81dLh0MCeVOQjPACXWQu8r +e+knN6xBvkdo2faKyx/dnYLaZnDWmJoG+xtIG4+8/uUImlzeCtNKs+mX5+xrfXFSq/f +XNyOD9JNoNxSAOIwlbT6dvZ5FzH7gfW8Tw15VH48ECim6PYwVsqZ9oTbWuuOsOSwQ3f 6PsV6znHABNyTYOYpSbotzDiy2Y547kJ+SDLlfasrYQbZeN63BcpYgAkpGpngR1WrV0Q Aqww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715372000; x=1715976800; 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=p6Gt9uHKHh1HnRu1uhOwPYNBg9fkaiXawsgjwu/g2rQ=; b=j0w6juuznJF6Q+Ku6zzyGqsc3FYP71oUA+Bl9kNq4z00AwyXdYpghERhnh94B09/5g bPnJxvIFoEBKkt7ufkyQrfcgD11vfbm/wA4f94EVsI3Z6AqbLL/y5qxauRffpcuvie0c NtNEsCD0JRA0+qNKbz4aqS5loz+fk8+f33vyphQ6jK19Ypj9r5EJqbGTJMS7Z5/vojLB HEHr4MhwG1ZIrdjAczpydZlOR4XkQsf4SSXQxsRjK2zf9DbsC1VHTnBcD5A0UG1YFhoP QxKhpr29zWS6j795clTPmkO652sP6CpPuaPhwPd9D6RfxFzRTPt1wplzaM6TGHS95M1W ixTw== X-Forwarded-Encrypted: i=1; AJvYcCWModdPd6e2PX0AblzVLBwYa2y8JJ6tWi6RQMwVT1GVwVzkfzIwlZOGzKgeQ8c7rntQfR2Vmv1pT6Ji4W3YJzmXMThcU11WxanZ X-Gm-Message-State: AOJu0YwmsvTsO8dfpzmtnvd/XWVKMj91YAw8qeaNiD2OTV3fEKt7ie7R cBZsPuCSHH12/3aycjYMZAjzQvV8C9TvToITmXy+4queiWqu2Ocu3C0Jzqc2fXJLdtdgARYJYO0 d+Q== X-Google-Smtp-Source: AGHT+IHLsMBUIwCHd5hp/OGLEudpP21Ef0vXfxq8qlIt/w0QmOPWPdN1qKJG2EgmCn1IU/UGOJJp5bTij7E= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:6902:18c1:b0:dc2:550b:a4f4 with SMTP id 3f1490d57ef6-dee4f33cb20mr954759276.1.1715372000164; Fri, 10 May 2024 13:13:20 -0700 (PDT) Date: Fri, 10 May 2024 20:12:43 +0000 In-Reply-To: <20240510201244.2968152-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: <20240510201244.2968152-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog Message-ID: <20240510201244.2968152-4-jthies@google.com> Subject: [PATCH v5 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 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 Reviewed-by: Dmitry Baryshkov --- Changes in V5: - None. 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_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 May 10 20:12:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13661910 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 E3E3B50292 for ; Fri, 10 May 2024 20:13:23 +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=1715372005; cv=none; b=hgGCNdmJJ3I8ECmYkI7bWhEn5dD4PxFztMcCcdNxgn7wTkdaru0Jx39ccDmLzZXtpIuIz03fOjoNXuOeFIbXy6Ocdmut/BVcXPBHGequg054KS7xjpFLr+iiwdZ85FYw3GY+gHfBlGCNRggJmCiC1JyzGVtTGeK4B/jXnYCt73M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715372005; c=relaxed/simple; bh=hUB2oms6xp9c47rZp7BKMmLVOt10/JNv5LT/f7l1e0k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GjHabghu7lIBgidV3alHw//25HvYqNOThAsQJ2u97tecwifMps1xLiZpUUFiWixh5lPCBJwfRMsIQVV7h03TbrAxaXOG/BqgAENqxZu1wvtMndOmeBYjTq5L3qvsa7pmRz83+jXce6wxf/NR6XigQFVDOx3weQRZaWPppBFIsMA= 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=PH4C1t5r; 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="PH4C1t5r" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61be530d024so39710947b3.2 for ; Fri, 10 May 2024 13:13:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715372003; x=1715976803; 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=YhvBEaMPWNIcwJictLHqDEbzNX1B8hMyot5dxcw8pLs=; b=PH4C1t5rueWpAhKXhgdxN8qSwdZbn5v0UslS8QRVWfXNKOrlwUdy8l4MPfTx3ORdgL 2B2KmcBvNsA+GYarR1MckZvT2JnA0KRL4v0LOv/pwkGO9csHK6mB37JSgpGM+r0lYpKN Ui/UojmSw4SBimx/N5fzeXvZrTiS0MWcxwOP+lhMmfY9WJE9Ha31FUekHXVT/Kymkjv5 SMTRtXwkfZLl1Z8M0+IQkqQOKVoAhQLvKwC//+IXTtNbCdgLstOPNqRme0v0tdg4iMFs OVjloCY23tZZGqUUIOgCSCZVFlFniHnO4JhhgSW01KUAR8qVmg38KaXU5qTrLgYEjDk4 htEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715372003; x=1715976803; 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=YhvBEaMPWNIcwJictLHqDEbzNX1B8hMyot5dxcw8pLs=; b=typ0wRrx9IziSS+0dlNLLJhanWvtvWIQlU4JsfUQWXkWZAUM2FUQ2Odkm3nxzM5Roi xKUEt4eogbAmo1kfjVIWKGS0RgtnXbtdn2Wjk/VreIAGKiuaCFZb7WQfaenO06QgfOVe KcoGTR+8lTE4F7UFZ9PtGi3N1Jun78vq6hxoXPE5IIwWggTv0Rtk2nzebZWwtPprmCHJ SjMiwB/B/ItaREMT88OigHFiDFKQjDaa3SWuB3Z6omAs4dm73HVxz4YVv8TntLNhNcPW RyecoLg4l13nBzpkTgQqvqzbLBm2GF4mMn5kubx+guGeIuLLi+oVEPxRmq5VP22Eo+pg VHiA== X-Forwarded-Encrypted: i=1; AJvYcCVE8Pa4gFH4jQ3tzAxycrTQm0dhwRLbQvP06iWtroFjjqJkvVyjudnjswbvey12AMJmzJ3uMhkLv2pjHa5TvO4IfqIsrjdtXTK8 X-Gm-Message-State: AOJu0YzCJFGUrYtj5eom0jD9TXuWOO4r4qvZ+KmEgW1jql88LLIIUBL7 OP7Hf8dFjz4WergE6mh7OI27o6pn8iv6FqhqauG8cbPCA6/mEkG/SsnxTYJx3WlgNlu8cE73RDF TcA== X-Google-Smtp-Source: AGHT+IHSOagr0nWF2zL0Nd4uRaZ7DGKHXDXfOLIV5EwzElZtcmActJInDo022AlY6Ss7BHva64+9QW1t4E4= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:690c:3608:b0:61c:a9ce:3092 with SMTP id 00721157ae682-622affea282mr8824807b3.5.1715372003063; Fri, 10 May 2024 13:13:23 -0700 (PDT) Date: Fri, 10 May 2024 20:12:44 +0000 In-Reply-To: <20240510201244.2968152-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: <20240510201244.2968152-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog Message-ID: <20240510201244.2968152-5-jthies@google.com> Subject: [PATCH v5 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 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 Reviewed-by: Dmitry Baryshkov --- Changes in V5: - None. 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 = 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; }