From patchwork Fri May 10 18:43:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 796200 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 B6B003CF4F for ; Fri, 10 May 2024 18:43:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715366621; cv=none; b=OV9vEqO3hS5RbBBTFiZtgePrwz4ty/wt1oKUR9p8JdBWAJvZjlYR+51UssbQBznl3YJKjSMzwUcBu4kzZkC/B7BDcVpfunenhhu2mbuwJ9NzTEHyn5bUnAoJlRLrgsK46/AQbtXO9nDCD2jVoS6HIgaWZ++TkORhk1kO/7rJ9k4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715366621; c=relaxed/simple; bh=bPIwwSWz7vhLPkw2Y7IUkySooH/UFfl9RPgbQvpMT1Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qCPCyw0wtGxkP3BkpeXX7Rl4PupFqEDmmtHQOcQkzIxWUw5ure7Epy/r3/QgGLx/DT2CWz3McjaaavCPcjfocaHc+BdUsgj38GTT84cXTR57xAPgre6EODjRNbW0yFz3WpxFxwhcoe3aOXdRq2m7cFVXCLYOeUdhG7vxNTUt2NY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=EMaS2WYk; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="EMaS2WYk" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61e0c1f7169so41867897b3.0 for ; Fri, 10 May 2024 11:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715366618; x=1715971418; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=3leKVp6DbOZKt/BkP9hZjqxScIgMDd3b3vJx/j0Aby4=; b=EMaS2WYkbIhvSmYlF4THbt56fWrbxMNAFU61GNmmeRwGXAf3/nXb8b42DdQcWrE4+A CvD1v/fcygFSRp99Y31jGCzjTzO+iwU5piRu7jVfVHPAH4fsD1xCYMr8cVUgudkhBKyD Vv6avvdbT9eJm+BnZ08aI0X7HohEgF9RHWgvexzVUqjsyV6WtEAtzMyHP0T1E0dxKcra ARkBdnBqfZ+CGojc4ls3mLxrCkPuzBMLQfiEgbEHU0T3yIVJ+mDiDkWbHdidHJ8fQhJD V4RI7zvETjauRhFNaXIJLGKjOVBF7Pt4dehm4SKoI8vRspSHYSfF3lC1lU3FL79CRYsP L/9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715366618; x=1715971418; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3leKVp6DbOZKt/BkP9hZjqxScIgMDd3b3vJx/j0Aby4=; b=j7yryqfDfIcVSfnGRppGOy1VNAo18x/ExeRzP3dtrdYCoJDdIXCFTqWUCxSelhOA54 UjHCEnsalRJJuQ7/x/VsbUdWJyW9n3i+p2GiE82LLzgnDWJto8p2svLywHlPwgbhtbHU +WhsFlqc8apXpfiGxryQidruAcuOd5xhY3js1YtYf4GTm3MyLUz/gxOGSl5jf6s061rm /ghZSveQOdqa79UwFbEx5Kis+4TV/8mAq3O7NKWn754Y2gwYDEQpiu06+JJx/B8lCQkP 4XlgMUYrrw/298DnSZH298IfFoFcFW8SHZcwD5L2pajwtimPyOZY7JMTWPRwqUPiwvir AQzA== X-Forwarded-Encrypted: i=1; AJvYcCVzE/rrfzi+5gXaDCQs4fzi86ptNDai41VdqkX3H4OUhUvKhhj0JOocjcpijnlHXbA5MNn2v/uI85fI76y2ZGDp71GppNXHrzt+ X-Gm-Message-State: AOJu0YwpSlMdnhIZA64Fumc7pEgb/wIpkdP+Kt7rpZKuA36nOttO4PT5 p/8QVlRnXPgqJjaufQD7kNhSM38CFX3a9APhHCukfJoMdvrrSY3hqdUClE6rQg5+Uh/IrtuW5F6 hYA== X-Google-Smtp-Source: AGHT+IH0Hl7sTOqR41zDK1Dxc6Amfcy0YB0Fkd2Xj5M07oxreTYb6CYyg15guWzK5gZbo9fvojMWUZHuFdk= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:690c:6202:b0:611:5a9d:bb0e with SMTP id 00721157ae682-622af90c63bmr9600407b3.4.1715366617882; Fri, 10 May 2024 11:43:37 -0700 (PDT) Date: Fri, 10 May 2024 18:43:21 +0000 In-Reply-To: <20240510184324.2944101-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240510184324.2944101-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog Message-ID: <20240510184324.2944101-2-jthies@google.com> Subject: [PATCH v4 1/4] usb: typec: ucsi: Fix null pointer dereference in trace From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org, Benson Leung From: Abhishek Pandit-Subedi ucsi_register_altmode checks IS_ERR for the alt pointer and treats NULL as valid. When CONFIG_TYPEC_DP_ALTMODE is not enabled, ucsi_register_displayport returns NULL which causes a NULL pointer dereference in trace. Rather than return NULL, call typec_port_register_altmode to register DisplayPort alternate mode as a non-controllable mode when CONFIG_TYPEC_DP_ALTMODE is not enabled. Reviewed-by: Benson Leung Reviewed-by: Heikki Krogerus Signed-off-by: Jameson Thies Signed-off-by: Abhishek Pandit-Subedi --- Changes in V4: - Updated commit message. Changes in V3: - Returns typec_port_register_altmode call from ucsi_register_displayport when CONFIG_TYPEC_DP_ALTMODE is not enabled. Updated commit message. Changes in V2: - Checks for error response from ucsi_register_displayport when registering DisplayPort alternate mode. drivers/usb/typec/ucsi/ucsi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index c4d103db9d0f8..f66224a270bc6 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -496,7 +496,7 @@ ucsi_register_displayport(struct ucsi_connector *con, bool override, int offset, struct typec_altmode_desc *desc) { - return NULL; + return typec_port_register_altmode(con->port, desc); } static inline void From patchwork Fri May 10 18:43:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 796432 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 02F9447A60 for ; Fri, 10 May 2024 18:43:41 +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=1715366623; cv=none; b=nicgFHOYHMam1I/nwcr+DVpBjXujzsEjc+Ere1flIlE0OuE4KjkYNj55LHaOMUtzI49Qb4//vvFkkXJjgRYKzwzDan6uwkOj1C7r5oKc2qVrFsx0NOhJesIKHQwhATgc9MdnRbc02BDUiQS0Ej2v0aLVv6DCXiGtoBk2sy7XxKg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715366623; c=relaxed/simple; bh=gQji9l12Fjk6vAy1gBuYFgvwCdzi4ZJBVjEkxA6DHUk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fS+q5yyJeNXUmoYpTcefIoN/+SvtbUnO1TSgidMW7XhkxrSLW342BUZk1eTXEQt4EOf6SHUWo2gz5QQPBwfG9jw3/biPsRiYqZzuCsEVR86wuSZEIMS9OTgFzldfgBZrABogp9SImnEBNGwtQIVwRvCtehm+24r0PuU4EhzrTAw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=UPXYbBMN; arc=none smtp.client-ip=209.85.219.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="UPXYbBMN" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-ddaf2f115f2so3614586276.3 for ; Fri, 10 May 2024 11:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715366621; x=1715971421; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=gcZTWRljQX/x9I6RAMAcoKUh92qzwt0cLFIO8/Y0bdA=; b=UPXYbBMNcl0BzrwD4yEBs5E74eyC75moFzXMQGQAWs/ne1LdCUwkaXDMEpMvCaS4yB 2JIkMxr4JLhsNqDFvdeejx0ODnnp1D6Bze4jcyWypPWJsmfXhe6+kwiZQCb5nHh0OAys 5plfXXpwygQj3ebmTZ+2q5ynH9I+ccNjwJDHqQpTZaWN7ERsV0s9H72E8JiN6fVp3f8a T8agyjhODp1RLJtaDfEsFhx9R6f0fcZsoHi9rivQiEzdZpG4iTiDzBOg8W+19VX5a6Sv bchQtXMZnRpvX6gvcQ7rUzqzgdeFKkdyKVZ/IyhVQU7bDc8GBAq7xyD3tndI2KbixIGf NBrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715366621; x=1715971421; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gcZTWRljQX/x9I6RAMAcoKUh92qzwt0cLFIO8/Y0bdA=; b=iNbAsS3jssJdNXwTuv1uvARrO3jUW8RTzAiFgjMb2eL8Z4aA/A5BzRvITXotbINs51 2jgMxSi0khFxinBfBxqvfKwv4VT5jUMB/wRHnfh5YZ8OWv781pzeaIerGazWFDQ9qjB6 Z4IDkLBuRbxhWURExR6/stbVZ11n/injqJD05OGS/VAuyqER10kjdPc3fPek5Pkb8hAi M8LA33I6TaWWeE3Iolxv9z4brzglBdm6sEYsQPWbBrj7iMyhd2jgakZp4ZURiFCD/X6W heKvkg2qCenQkgvbxpYzzji8sVjuZwC9xWSqG7T98ZJYtqPvNcrZALBZ5y8oSMI9g46y P4uw== X-Forwarded-Encrypted: i=1; AJvYcCUZtAttPKydreBIHU6mUc9hyuqS/Fry7Nw5VIvx8TuUDhpZ2dZRMOzSdoodi0+nxUbJvX5VCvZ3uu1k6+/1A9Q2m5p2MSMYXgCk X-Gm-Message-State: AOJu0Yxy/RzsBcMPktgvHZMZhBQX6dT9dU9Fb8UZtjL/yDvq2C1s0b/a lWjDFNpIBXgRDsC3nEu/EdG8dax4cdtxSPX3RCHxHq33s2BdPGxfNk4dDGKKZeykOFT/xXlsyUJ 6Iw== X-Google-Smtp-Source: AGHT+IEX+Y0TwfXDXyAK2FWGkX+Yp7DciNo2SWMVEaaeHqCrTSftQYF1VowZjG+ms1EStcbrcZ9NIePZn7Q= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a25:fb06:0:b0:dce:5218:c89b with SMTP id 3f1490d57ef6-dee4f3595b8mr317092276.5.1715366621008; Fri, 10 May 2024 11:43:41 -0700 (PDT) Date: Fri, 10 May 2024 18:43:22 +0000 In-Reply-To: <20240510184324.2944101-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240510184324.2944101-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog Message-ID: <20240510184324.2944101-3-jthies@google.com> Subject: [PATCH v4 2/4] usb: typec: Update sysfs when setting ops From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org, Benson Leung From: Abhishek Pandit-Subedi When adding altmode ops, update the sysfs group so that visibility is also recalculated. Reviewed-by: Heikki Krogerus Reviewed-by: Benson Leung Signed-off-by: Jameson Thies Signed-off-by: Abhishek Pandit-Subedi --- Changes in V4: - None. Changes in V3: - None. Changes in V2: - None. drivers/usb/typec/altmodes/displayport.c | 2 +- drivers/usb/typec/class.c | 18 +++++++++++++++++- drivers/usb/typec/ucsi/displayport.c | 2 +- include/linux/usb/typec.h | 3 +++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/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 18:43:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 796199 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 CE5FB487BE for ; Fri, 10 May 2024 18:43:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715366627; cv=none; b=Wgoa+uKgt4VxdRvrJS3F+ahxydSo7Xsp6H/5R5E2rXGKpiLAIBkTuT0rJp8VsdVwDVhcx/ABLs0QNAnvqwwbd8JB5mh8aMPEPi9JxzzTrnCoGKjdKoBiW3/g+wWEpiyoTrEC53EriTFC9PjjsKAg8wQWOgi2JtE8qcyI7O8jtso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715366627; c=relaxed/simple; bh=5Dxt8M/uMnrYaCujm6SYe3p0Nct6vbEeAdJLQT8qgX4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QOBG+ZYwb2uy9iotmIKG5RAIucww9OUxWHGvOn54eHryhXKqErDz9OcRXjglKT/Pk9NHdwv7cowxh+KnYsmvRzNS5cw/5a9eP+W/JiPVi2klQqqg8q0HKPYigFnfXHa784zFlFROSlYEheTrJOGcQweQZpU58lW8CxbsYzf4dkU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=BVGADxvI; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BVGADxvI" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61be26af113so39161217b3.1 for ; Fri, 10 May 2024 11:43:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715366624; x=1715971424; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Ibv/f3Jsw2CQCASuGotHQItld+LQXS/bJ8cmbunskpI=; b=BVGADxvIsseFytloloa6J8ZK/n6MXRxCP3qoLi7FVIbuxg5FCrSc4u+Z32RmEqeujL C/cx4acpAE93nY41Nb3SqOAKTfyjZFQ/DsTxYaoGGhkYPLIvf917udWjPZM/6F69YlF3 f5HArZZXzjJoNwEAdZhNWTpqbb1UNQlQunPJ74Y7pzsN0F92hi7PVvYTtbNnJQq+Oh7O MtLmEvHgWH9LrjeVVK9m1j+jseFa5kKmuapNBS8yNM6JqAjkmuTj4xEOkKKuE/NoW6Dy T2e0WEwODDquHxxrtnzYzEMrkdVjomt3RKVd1ZRR1F59no1z1BHbmXeOzHoNa/a0OYNU emQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715366624; x=1715971424; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ibv/f3Jsw2CQCASuGotHQItld+LQXS/bJ8cmbunskpI=; b=DE45qVJcCroiBDHb2jE+M9yWTaSwmpuqMmBNAbrBSEA6uWqe2lO1Jws4UcwXyCK/kY fdH/qBLqsRPeo0YlUMSWJi/qwOCmb4zB0cHqfX3Fbq4T2aHth55Mhg31pWeUXW+97p8A xcOBxkAkU6L5l3tEDFuhzgZbZpwb0cXx/+g94rK2FLwjJ3XYp4W5EyW6NqwogKI/66ZU yIBdC0DonQlWVpZBzqS8Y9ORAu90u5kpVioBoxCTEqTZIngi1eBP/RIIoDHwHn0rA6wr /6Y29R/PSwRPJUCPOBvw1VGXrzp9tlZGPlzYZ07MkQsvI83/QZ/cpwWsglVvMfX3MXRZ /H3w== X-Forwarded-Encrypted: i=1; AJvYcCWS+PoT9Nbwy463nAGRvzPL1NUSdPmM5cpJ7a0EURJMqrnwI4bSqw8J0AiyCOk9aOGnwjZJfhKTQ64riZxTMThRsBw3j/zCjuWO X-Gm-Message-State: AOJu0Yxl+KHoIJ0gvIBDG4eiQq/FuVp+dq4G+uJuxEgyAoXCZrEL8nHi Am748J3keD1zWY/tujjkdBI5M0y/nKq+ZRP/PIbaYnlzTXeVhuphsVkh9RrVJ6yguMT4x/x/ad1 jwg== X-Google-Smtp-Source: AGHT+IGDfBKNUEYIqbIlS5Fkvoe+iha8Qx5p07lHU3gwnZ3n5tfA9OQISwkzlfUYlssG+VExqcdQVtPLK4A= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:690c:6c0e:b0:61b:ec22:8666 with SMTP id 00721157ae682-622afd96b2fmr7843577b3.0.1715366623917; Fri, 10 May 2024 11:43:43 -0700 (PDT) Date: Fri, 10 May 2024 18:43:23 +0000 In-Reply-To: <20240510184324.2944101-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240510184324.2944101-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog Message-ID: <20240510184324.2944101-4-jthies@google.com> Subject: [PATCH v4 3/4] usb: typec: ucsi: Delay alternate mode discovery From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org, Benson Leung Delay the ucsi_check_altmodes task to be inline with surrounding partner tasks. This allows partner, cable and identity discovery to complete before alternate mode registration. With that order, alternate mode discovery can be used to indicate the ucsi driver has completed discovery. Reviewed-by: Heikki Krogerus Reviewed-by: Benson Leung Signed-off-by: Jameson Thies --- Changes in V4: - None. Changes in V3: - None. Changes in V2: - None. drivers/usb/typec/ucsi/ucsi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index cb52e7b0a2c5c..bb6e57064513d 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -963,7 +963,7 @@ static void ucsi_pwr_opmode_change(struct ucsi_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 18:43:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 796431 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 BDD514D58A for ; Fri, 10 May 2024 18:43:47 +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=1715366629; cv=none; b=ScKrXjHOYeRhGzA/9HnslSk+dzYZJCc7BXboIKC3UHTnz1B09CdLvUxyqGHPzekgeboxDNqJqsKsPz6lXP4VfFWk6ADC3siSlTWlR0DjgZxImlEs4VQQieTEc4D0G2XEUms0otxRYeKvfDvj7+jMAO4T5j4t92zhanPBpGpfsBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715366629; c=relaxed/simple; bh=R0kPcz2z7KHQtcT+DCQun4RPsuErPgcBNGZMQbxuRmI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=nW0SSYohORbv2KtSq/nfvp5rWV3x6dpRGdhnHCWI6CAx4/y4SxNsztgisFpuEvMXTgsGXD0aZnYj6p4oqwmwUO802xV0qv5oA/Wl8CAbvE/skcgG+/m3U1VNuQ87zRdMkW+0d8Xn4cR0/x1IW9ywxdEfgQDyB17c2rpK+clLRQY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=XhgFULAD; arc=none smtp.client-ip=209.85.128.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="XhgFULAD" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-62035d9ecc4so40628147b3.1 for ; Fri, 10 May 2024 11:43:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715366627; x=1715971427; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5TEblfXliubmthqHAqJA2jNdtqm1t1yD50gCYv7pJus=; b=XhgFULADE46oqk5FpKzQer23oOo97i7TBoKoeteoHxUBHNuHCPWnXvKdZNQrVjzI9g /cU/NV3jJ6FhUVepkLpNnw/MUqZ9jRrP9zsJjFxDHwexN1R1ghP1FwZliTXMDWNk3E7b 1QJmp3pPrp/41fg2wC3N3mMoj1ed9iTvxWNG6z8WerFrmT+UrdiEzD1faLvpCQx3GwPm yp1c4ZATrUnxu3OjSAS3px7eDx0ICMC5tevh6MkcjbwmchHB94CcHbRxznmJqmLbu5Uk LxuksmOr67lIagAgYJ44qsqCQ9rzJ7wFR9A2wlj/JkVJlcQ5Ljgnqw/5P/khHRCGmdAz 1M1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715366627; x=1715971427; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5TEblfXliubmthqHAqJA2jNdtqm1t1yD50gCYv7pJus=; b=qY8V+A9wYUdfsZKwSmDaeLiBKPWqEeEghE7kprHQyCs/CDsbpVo5oFPgigyCB2PESx R5MX4vdPzoskstaBCsR8H+lhrr2tLn7Xt5MSy43syiGS0UiFtb4un3HgrYfz5H15kdJj iUUZLxO+7YYR7Ac+iXveQEnk4UnJRVcd3b1l4Ee/41xmdM3YxwulVzmSKF2rwpxF4Fkx +bdKCd0qinlaTIRySXWY3M/q3+K6cUDIHanzoou7/qM1KCOkw0pHITqfwStTtfO/K/OO yngKNEbiOZPOHAQrZKe4tI0o8pL6DXHnHhYxS4TrFIoa0R9NcJirXb8g5RvoBShbydDs CGOA== X-Forwarded-Encrypted: i=1; AJvYcCV8U+wI3Mu7obdY8qSJNnhsKLRKgW4q+keXXIrR3tsdDfn3F6yKEdtkot/KAurMSyg6hLTLlSItQLT7BXs9ebbTL4Mv+yfB35hO X-Gm-Message-State: AOJu0YzW5WYgYOAZUHYY7sLEKDsAiixc7ZN9922S+xlSckWZuQ0CMIXn FcInVaNKc3Os/byHe3tgMxz/M7DJUgSW93dO8YfUpwMpbSqZ0l5cik3W+Rk9HkIM/qtxejzTRdN 7CA== X-Google-Smtp-Source: AGHT+IGaWgy+lzvqz9wTSsHNfbW5bue9orgmN1BHek+1YZUAMaba3g5YRlXLvCXcathhN4gsL6Nmrz7YeF4= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:690c:3801:b0:61b:ec81:3f3b with SMTP id 00721157ae682-622b0038dfbmr8623737b3.5.1715366626864; Fri, 10 May 2024 11:43:46 -0700 (PDT) Date: Fri, 10 May 2024 18:43:24 +0000 In-Reply-To: <20240510184324.2944101-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240510184324.2944101-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog Message-ID: <20240510184324.2944101-5-jthies@google.com> Subject: [PATCH v4 4/4] usb: typec: ucsi: Always set number of alternate modes From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org, Benson Leung Providing the number of known alternate modes allows user space to determine when device registration has completed. Always register a number of known alternate modes for the partner and cable plug, even when the number of supported alternate modes is 0. Reviewed-by: Heikki Krogerus Reviewed-by: Benson Leung Signed-off-by: Jameson Thies --- Changes in V4: - None. Changes in V3: - None. Changes in V2: - None. drivers/usb/typec/ucsi/ucsi.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index bb6e57064513d..52a14bfe4107e 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -812,10 +812,11 @@ static int ucsi_check_altmodes(struct ucsi_connector *con) /* Ignoring the errors in this case. */ if (con->partner_altmode[0]) { num_partner_am = 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; }