From patchwork Wed Apr 24 01:48:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13640945 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 A3B2A134AC for ; Wed, 24 Apr 2024 01:48:46 +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=1713923328; cv=none; b=J5Z0nFQIfD2j6uOOOtkoibIeDn6EAszTSJ9tCBDZOUGlsJdlqch5mDloM7+lpQY11vnCZSdpfvfccK/wjsMJ5Zf0JYJsmUTYH+oec+fIJJzWl1akG1IG6ZB+9JHbYusEcDkRn7HUbzQwom+ctkt3JaI/s8d/T/8Qg42WDHUHwOQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713923328; c=relaxed/simple; bh=DkEhHOa1YOY/idk5PLSaPlY0Gz579FEwlh+ZoODqcWQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QHXy2dJZr2lip0G6/h7yMHQrhEAGD+mWcNjfH1PULbSKCf3VeEaPwSocJJmWeP0izF2urwko3EzoNP7IN8btW23/ecmKCe9az5sGDDMNEGBZFwHRztx5QGpNk9wfYOaTHJlsD/zp3qldqB7n91dxe0XfUE0Uaa4Eu9JR6/s+4Ns= 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=ZzuuqTjr; 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="ZzuuqTjr" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dbf618042daso11563574276.0 for ; Tue, 23 Apr 2024 18:48:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713923325; x=1714528125; 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=8GjkODbBEJ1z1TWojaRQYVjYLRHWjXoJ2bOwq1fsJLc=; b=ZzuuqTjrou1v1lQ2g0S4HoyRkZ1lSJKLigPx7YYftFUFPgENZKSY+JAAcL9oxF51tB 7GYGBuJhussNiMipAQRxBr8+7GZ0EJKRDzsN/eI1RTHQkd78DwCc+ATZz8ikHH9rHkAQ WsDC+wwaLxAML9rDQjkg4L5XXM5YeyTttXIz81L31tbrwOyCWV4O+VPQN1tzjWcvRPva 8TKtPnNJPKWd1Ycd29EcJqqSVGiiXNHLigdw4TmJzienMaiiCNJkW8f6u7cAWqb1A0YJ UQQLJwk1x9c6OJc4n762CToOgojwGSxRfc0oKO++tWV7w5F+yf0j9Ei7mKCcoiamSAVO KvTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713923325; x=1714528125; 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=8GjkODbBEJ1z1TWojaRQYVjYLRHWjXoJ2bOwq1fsJLc=; b=tQrQCG0fG3B5VxTHH20b4Nh3DhnrY0cyDhD13BxEiHrpB/6XhOoGzOLcamc+1kGgZ6 jLHJa+xt1KAsEHBEJpb0n0a6MGdTYqG4Q44OlfaFaIg+4E35N/qYWOwTq5TLcIqA2BsQ Lz6PEIc2biWKSY6OphxkRrvbo81Vj3wFIVD8x+Lllm2kZoqSoXojA7nnoah0GqeZotli MoawMwptlHVZW8a3ZRjd1yMEWArFWsq4jgIML+LjNHaD4tH/FoldBqCdodXglXo0CryZ 3H9N3VAJ9fBELF54L7tWsriWgPgeka0dNvXL7DxO/GJASpb5/sGFn5uAS5STjU7Yq1If +3SA== X-Forwarded-Encrypted: i=1; AJvYcCVRdqDrxMZzfdwt9TeumYEpE3Ff8hfXAJUqy5nsD6OkrqamBnnTp2QyVPFMtg2xUFZvYrHa+9LyYht5BbjcRcNCgL0IeCfLF8Zn X-Gm-Message-State: AOJu0YzsGCKdy6pKXLpaBz4yH/S5kwp4cnyotrg/riQto2R8ifuj/gG6 PrqMS0C1Wrx/elxCPrNDDuOX9ALLrfAqLAXmIXpJKIceEXNYIi5sNrcdQvLtF3t1wi8Z8D88Bn8 KMg== X-Google-Smtp-Source: AGHT+IHqRn99HKG8GFzllw4oydn6oguqocBMLsNVpEhT3sxDknYY5ILkKUekAtW/lYM18qpYQB6w/FSUoaQ= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:6902:218d:b0:de5:c2b:389b with SMTP id dl13-20020a056902218d00b00de50c2b389bmr104786ybb.5.1713923325627; Tue, 23 Apr 2024 18:48:45 -0700 (PDT) Date: Wed, 24 Apr 2024 01:48:18 +0000 In-Reply-To: <20240424014821.4154159-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: <20240424014821.4154159-1-jthies@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240424014821.4154159-2-jthies@google.com> Subject: [PATCH v2 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. Return an error from ucsi_register_displayport when it is not supported and register the altmode with typec_port_register_altmode. Reviewed-by: Jameson Thies Signed-off-by: Abhishek Pandit-Subedi --- Changes in V2: - Checks for error response from ucsi_register_displayport when registering DisplayPort alternate mode. drivers/usb/typec/ucsi/ucsi.c | 3 +++ drivers/usb/typec/ucsi/ucsi.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index cb52e7b0a2c5c..f3b413f94fd28 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -361,6 +361,9 @@ static int ucsi_register_altmode(struct ucsi_connector *con, switch (desc->svid) { case USB_TYPEC_DP_SID: alt = ucsi_register_displayport(con, override, i, desc); + if (IS_ERR(alt) && PTR_ERR(alt) == -EOPNOTSUPP) + alt = typec_port_register_altmode(con->port, desc); + break; case USB_TYPEC_NVIDIA_VLINK_SID: if (desc->vdo == USB_TYPEC_NVIDIA_VLINK_DBG_VDO) 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 Wed Apr 24 01:48:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13640946 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 AFE89182A3 for ; Wed, 24 Apr 2024 01:48:59 +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=1713923341; cv=none; b=nF4tQUFHTBLtk9b+AGP2GzPjaDQ3qNY2D6A0GmwDfqEcyelrfJu9t9ysicg0cstcvfwwUTIFvaKf6FvQkUQAcRPJ229qU+Jty3PgOALLDIXyKdqY+KGJ3tmDkI6G9pskL4KVuhU86A86jRBUpDkB7jcMfLJx0o8xq4tlDz2204k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713923341; c=relaxed/simple; bh=m1HtQmNf4KxCI7tQe3eA9QXlPOTeo26skECh7AV7JzU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=P/kjT7qGPCpdQGbmDhTUEvnqOnP1ZNkfZM9AVX/BWxBfyqXj7DBL8W20NYi8kLjR95cirt5MAo0wHgSHSwj/cV6t6STLnIG7DyNC9vV9JTf8/4+dsNDYDokeOzrKIoYGhQTa9qJ0nC24Xa0WmELP3c4Pgadsh35XiyLxFmNsFEE= 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=CXkE/UrG; 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="CXkE/UrG" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61b6f415d0fso43247687b3.2 for ; Tue, 23 Apr 2024 18:48:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713923339; x=1714528139; 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=cwsr5zimwwl7iB3IB5gm0hd1CCE5USVnmuwHUKdLC78=; b=CXkE/UrGQnlycONR5ZDkxjK3Gagc0IAHOlKCKTzeHxBklZWBi7ypN7okFeqR4oCIgC Exn0ZTRuhfxAJEJ2J7em9nbS1OVK0+jvCrZulH0P+SXwKLrFnk6UhFT5J1XwVGcD0cSV j2HgqQy+pAgfSqNVUbWn9dXeaOkUr3u/rvyjzgchkht0nNkAhLExd6/yn1AQkudYT5+Q Xr3c7zP+5ZD2OvdRFXKtf22WvLqxgdQ3pEX+p74gZsZOAhuAnVjW6JFTdm/hQqYpXmEg hkry37OXyOmu3ljFphEUmfAYTuIrnoP8mXBQQrc3zBVW28PTDSvcQsa7A/DAsur1qTaF 0HNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713923339; x=1714528139; 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=cwsr5zimwwl7iB3IB5gm0hd1CCE5USVnmuwHUKdLC78=; b=G3v+Fh4R6n5hHjkim1bV/WZJzqj4/dPN4ggvHWAYPzi57Gsdzc6UGJtVIv5d4Wqi1m yT7jU8mDhB09bPer1pJtnFfcpqfY7DgbTpUNEOeEUNRhnIE6qZD4mw6dmf4H/2x7Ka80 5sN4KOhyg3JzsFI9DRvgNCs6GQH40V2bru+5ek+j4nDX8i+6LhlrVBFoOQxSQTxW/spE stSeYhgextih5VPkMPYeXfl1/sMM65rc7HFklVRR+trLlSQkCam77BawBE4kQT/rItYU RDdP+IsZ6mNoknK6EJL0WNL533OjrkOOpUlGbeNz51PHbPXUUaK5/DGwSPbinjMLPhaD AYlw== X-Forwarded-Encrypted: i=1; AJvYcCXgat3/whmDv+b1kmsNDfKayjm6/oH5wXdXlxBuGUQAz0jSudagKNi9Ys2ESP1kR9ICePP8T0MLTULpjbFrxfih43VZdgiNlpNA X-Gm-Message-State: AOJu0YwO+WeAhOngsO7xYIfKIoYi/6ZeXZOX5/HA1AyHXOM4bCuNpyGU FJURiGmVbCWeIyGgw3RlT1HIltycMFmM+DjCgXxJPxihxPIii/EMhs0XgOeKBTPZX0mz5Y8shG6 7Pg== X-Google-Smtp-Source: AGHT+IH1BHhOw7kyUiS+4sIrPrs9btWxNAO8b7+PXhv4qFdWIlAm8r+0yDNmAnw6wb1NsagAOL+uG5JbIG0= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a81:7744:0:b0:61b:1346:3cd5 with SMTP id s65-20020a817744000000b0061b13463cd5mr308854ywc.9.1713923338677; Tue, 23 Apr 2024 18:48:58 -0700 (PDT) Date: Wed, 24 Apr 2024 01:48:19 +0000 In-Reply-To: <20240424014821.4154159-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: <20240424014821.4154159-1-jthies@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240424014821.4154159-3-jthies@google.com> Subject: [PATCH v2 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 Reviewed-by: Jameson Thies Signed-off-by: Abhishek Pandit-Subedi --- 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 Wed Apr 24 01:48:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13640947 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 81AB879CD for ; Wed, 24 Apr 2024 01:49:02 +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=1713923343; cv=none; b=ULnLTbqJii+bEBTkPjjhWKZ5BF1ABVTfbwnwUw6BKyGrQxxIrYoyNSWKcNuIXhMQcsBCxzUQD7/GXcRMPyVRe1fHFhUYRpdyjE84BdP6+PrhWvtb7kn6FJ4BvFVA1YkD5KmoxggAHS9gEteAq9yzfg72SFmtkr3uvlXlbIAFNxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713923343; c=relaxed/simple; bh=aOXxLPtNiFPouK8yihnuWDFAFsJNURmfJp1ITib6WMQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aU7szwFNy7KBREW7Wrhj9a4xekzsLkDXjsPE8Dh9pbfavVrsQP3BO6zpn7OtPJeg/IpjVYe9PCr3NF/Sjqz4KBjNzZYARVXZQJBDZ5YzSvfsjYVr224Z1uZ18R4XUCntn4TTrru4tObUxZVBFhUJJpjPPNUFLwF42CwMy757EGc= 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=CzYauc2c; 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="CzYauc2c" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61b330409b7so95045547b3.0 for ; Tue, 23 Apr 2024 18:49:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713923341; x=1714528141; 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=ezOeRF6HXEObMPJXRNe8KMyl6QUSbmrUwM6rPAOdEII=; b=CzYauc2ci30VygHEG7Zvk9z9nUGzcOkrTBOd9QbmVrOlGyP2dwJHjvlmVyO8jr03Nn NmxLtAQmwb59bfT8adjI3Xd7BAQ1EYu17QyI8qjE5CJcmPIjsXjMgK3MkkJ2+bAGa3yK kbY/CLxydnJFWqerjuDWvZcjCXSqy0JQdNMe5XfveRayUbAoZko0nK4sn77xvZ3FH8pB bwHU1OorTf6tNTK0uCtj5Rk2ccB7Le4d3Fq2cD21Dvet/Z6l1sedAExLg7hFfyHWiq/M aJpNUL/+3JNflQdvkzcuV4Thvgh+m2xtKTC66RK3P1QXl0g06O8Jb9beAGrHEZoLznXY PgGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713923341; x=1714528141; 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=ezOeRF6HXEObMPJXRNe8KMyl6QUSbmrUwM6rPAOdEII=; b=sO+2VfCy1KoiyU7G415q+wPLVLglTbEY4wzk6dcflFNpLUXZVKtY7Hx/Giv76B4uMP Pt9OtM7/t9ktBza2udcCXkjubYA5HS4aFjlcVv/rzN8bDyUt3iONReiLf02WcUze0JDN 9JnRjKig+XeYr1qWhp8bSz6EDwoPvmFrcXhO8ZBokLr7+eu32wIt0Ia9GYeFAQeFF41+ F05zx2YXqSKT09iF1jGz3+3pitiA25VdMDW9C2fqLPjG884HqSXm2OgPfinlRQWedKKA Ye6LDmCztX6ooOXVQ5IZhPwotZdgAxAN3UI2E4aInbj12B6TAXzfFTEZjOuJB0a6hVOB qBDw== X-Forwarded-Encrypted: i=1; AJvYcCXTGmpPYPAAWTiKE33FI/h9GN4f7rN0SnKYOiYLDVo24iv281Ut4Naf7rJJm6aDhSvdwTcwH6/qeIO5Q9LV2smrz3IvBmHY/WWU X-Gm-Message-State: AOJu0YzhhZllgRoL1p+lVYQ1mkY6Ui3fRl0vbtcxc4mldhfdOUsJGAip IRoq/9as9/mFNv6TxLoLaAlhBP55ltO5M9jiMdgIxuPm8IZ5elN/silES74B6oNNdlKvXA98vmR hEw== X-Google-Smtp-Source: AGHT+IGRd1L5GL95YL98E4tl3AqHl67Uo03kuUYoM5eqrwQBKhXNMZvglsOEK5fIZKjCXkdlxIkkFCTGD80= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:6902:154b:b0:dc2:398d:a671 with SMTP id r11-20020a056902154b00b00dc2398da671mr358301ybu.10.1713923341480; Tue, 23 Apr 2024 18:49:01 -0700 (PDT) Date: Wed, 24 Apr 2024 01:48:20 +0000 In-Reply-To: <20240424014821.4154159-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: <20240424014821.4154159-1-jthies@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240424014821.4154159-4-jthies@google.com> Subject: [PATCH v2 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 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 f3b413f94fd28..f167891e3f79d 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -966,7 +966,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: @@ -1250,7 +1250,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 Wed Apr 24 01:48: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: 13640948 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 E0A8F1C6BD for ; Wed, 24 Apr 2024 01:49:04 +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=1713923346; cv=none; b=gafzn6HBiwGQ44vJVnK/WEdaLy7DdF8vvKp5nEAKVPY41TMVOLIpMsnScOMUNVjkVIaOocYdgqUy0GQzY0uXsWAkZIuouvTfsfrTPRX4fRCfNGQ0NqG8SBOqqwa6oZI/leOg3IE6GGeoeubDvLn3rfNhXpjIxyvD6I3gSV7addc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713923346; c=relaxed/simple; bh=O8wBo3jMW91/mXqgW1PShQ2yxrd/2XtsUuJ2TzAYSKw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fxAqnufgLWfhgdEtF6zNbRg+/u/SfEA02uOCrXzfhx1JnOlA8m9NLkYTAjX7QrV5DKCKJV7hZl+MgPXRc+I38vQCX4Nzoa5cDSf/Q8WBlnO7Vs29bSctwloNrbqTR7yVXMDt6KfqBVNzdn8WO7OCRCKkXpGyAzcmVJ5ibcJa5BY= 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=Sr1FdjRv; 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="Sr1FdjRv" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-de45d8ec875so12164618276.3 for ; Tue, 23 Apr 2024 18:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713923344; x=1714528144; 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=JDrdqA7hSwKXktN/HHZfNNu+trfOtehLiAtZBEVkgVo=; b=Sr1FdjRvL5uJyRcVG/GfPj5PqcKHhbpHPtQwKnU8jgScszaddSO/lWXTXGBJG0JOD+ yq3mdFqz9YO7u0zihEQklvM169oIFBS/TJzK/mYnui8/7uyQRezVqYoRdwapmHvysBnl AX+TOkoMpQ3NpXe01vCMbJ53huppSqcunGef+6JWQaVR+ebfeHeyJ+O3Gklz2hX8pcU0 X5CowR/eoABNQTfnJaWfU7pDNfnURqdyHbKEoA697ASHeccZuFfKmxMAFWDpUdVQXEzX euYNDPj0D2Om+jxM50DFVSNF2uPA58s73d5NIBj2cDFtfk+H3HZ/ufpd4p2gDQ3nTm0d E/+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713923344; x=1714528144; 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=JDrdqA7hSwKXktN/HHZfNNu+trfOtehLiAtZBEVkgVo=; b=jVLlGrY3BZMEai3cWD8mL4YYP2862B8IuwHq8S3VjHubb49A5nQDcHWTNALdgeolfr GBmM9ZGsg1PTuwnjGE7ILoegCPd94aHt82dTUFdx8HP3AdbMpXQGf/G/DbX+6qY8YbkR pDsMmpag2EZDYMksrzwUTSn8kiK82FpZhVWfhmMvq1iYFk5WSc8XLkZrIS4OvX9AKaUZ XdBtxBLJIsOQPoqr8SdXrdVGtdDBuDhEXMqbriCfd9FUKxk4S5oIAMyNGfxCJbOghEjU sjbBIwzOEhy/w1kihOYVPkBvAaI51vNX5q0wciy6gGvGwkDaEEj1Rbs+6doBZ1yW+qKU b1qg== X-Forwarded-Encrypted: i=1; AJvYcCV2gUAfN96xGsYM10q3CH+NS9XT5ckCEm3ADmdvWmJW7Vz8j8uqRFnb5+Xf/Z6eyJJCc5PiiPtBA4QjN+TPzIuQ9sMW6cXmv/B2 X-Gm-Message-State: AOJu0YyzSV/1B4R4NGX0TfM9BycP/q325j6P5ahWomjYR4trr0KnBQZN RvbnMfAi/PIUkXcmQ9USjFDXcDGKrnNsvrImrBv95tPeBftsUerG6Jss6Q0W0dQHTjdmX0TthtS v9g== X-Google-Smtp-Source: AGHT+IGzPA/NrAQVNPZqtW1hoV5x3X5BTGRzZh8/ME0TGcv9dw+bpp5t8x2CH2Htl6Uyy00ThOpIRjHhwtU= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:6902:2285:b0:de5:2325:72dc with SMTP id dn5-20020a056902228500b00de5232572dcmr379795ybb.5.1713923344005; Tue, 23 Apr 2024 18:49:04 -0700 (PDT) Date: Wed, 24 Apr 2024 01:48:21 +0000 In-Reply-To: <20240424014821.4154159-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: <20240424014821.4154159-1-jthies@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240424014821.4154159-5-jthies@google.com> Subject: [PATCH v2 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 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 f167891e3f79d..994b8a6b6be96 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -815,10 +815,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; @@ -1141,7 +1142,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; @@ -1175,6 +1176,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; }