From patchwork Fri May 3 00:39:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 794826 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 0D1F3FC0C for ; Fri, 3 May 2024 00:39:42 +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=1714696784; cv=none; b=hEV165QHig32hzLYUg6jLrL4ULJfSyg7WznJOPeDt/MA9KM8MBXxgdvwdAY2kvpnshB+94Q63tnwDtI0gl7y1D7/xLApCj0G1gVQtYpxC8aFZOvrM55YHmSL3CRmsA67uwMEBb8JJe8oSuaoIA/MZ6qaxVyT12yy4xUnSbwyvVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714696784; c=relaxed/simple; bh=UP93LeOYyXTB+HImKxRgh7AV1DkTaG5cFD8ox7MDsiQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MpBr1/Cw/haTHOAaYhh9o6iNS788YKOvdLCo/wQbNQiCFRiy/Vb8+Gadk9FLx/awcnJDnj/I8bq7mbkygVm1n/xLI8LwiY38EEUeRN6+Wka6Ad1HuDmDvrFTZvy+6xAeGi9GTTvymsc31ZJPLE9LHSsO/Lrkigjo3ZjR6s8K4tA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=JKheCkuq; arc=none smtp.client-ip=209.85.219.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="JKheCkuq" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-de604d35ec0so8245220276.3 for ; Thu, 02 May 2024 17:39:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714696782; x=1715301582; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=y7QwxP/IR8IteTIhBkWFiOVh6L2OPrMA6wzDacMquRE=; b=JKheCkuqmzYFl1QYiE6JECplSgRWMunYiDmQtviLllTN8XRBZxBs+Won/AWf92PI3x MdILQ5EaVyYePNfSioCzUGzUA5qouPnoHVx2Wdc4Mkt6mrSRup2hOjz0Z0fAI53o010F TGbOZvv8IWcNMF43veWAzAlr+/b4HN0adWXu5VUCUjgVvBaaQp3Z31o75bpiATL5BSPO vQ4Oi5RoYRxxC2ppiVbCYx9sRp8/MaICnV8ZFx5s4TG0+/0RQ7mh3nsdza5S/e3GIwJc G1rbB9534TTN0asHBMeSjNwXgsPKI5wk38sLEGfOp0o6dxB1sqgVUTSY6qHt5b7XmWyF 7IYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714696782; x=1715301582; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=y7QwxP/IR8IteTIhBkWFiOVh6L2OPrMA6wzDacMquRE=; b=dd1MnhTa51gsAExFaz6Kq3T9I0if1xY6SrSTbShnHeEEDSosClPhrLPB6K/9obNzGn MnUAlKSW/+WV6YBy3kPyVf10ymJlDQNTkED8fm5Qa1t+f/iPHIEfM8JlwXEDchqFEx2i NGpzjDk2If9dacu57lumonq+21o/a7+MZdrtONX9EN677pLoQS6qbd3GXtBgeKnyL3Rs Nyfgo9BygBHKj/026G+SbAC1wB67/3V9Z3zfSmSj03peMzt+yT43qPAku5AMlFG9vCll 7EfTV2dNGcHjvTxm4eThdeOZ2gt7nTXPqPYMPCZawbD5Ige2MI6Q2kAVjLDCIDcgMJPX EWSg== X-Forwarded-Encrypted: i=1; AJvYcCXLmwOIu7WQCsWcequDMWCVA651tdARLemUOYGI/9MtbE8FW+FsocFA98OBAmYr2NgWyQjA9Y//5uXztG9NRS9uHzalylmGzWAD X-Gm-Message-State: AOJu0Yy3ko9G6xRrzRAVDvG0Y7pnGHfi/9IYbYjHAg5Qm4xmV54mEoqY 0I/3WDUR5hHfEW/VWpyancL/IQD1mvMtoxVC/7hwbNJoUNuE+wIKiiryjA4SXI45tE6o8xHyvb3 w4A== X-Google-Smtp-Source: AGHT+IGA7rE3BAM0KG2lZo/Ms/y2c4C3BtZJwhhhC+5ZNSIrGkbjl7DC+rrug/J1iX6eTsVMQyasB7za2KM= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:6902:2b89:b0:de5:2325:72dc with SMTP id fj9-20020a0569022b8900b00de5232572dcmr426447ybb.5.1714696782126; Thu, 02 May 2024 17:39:42 -0700 (PDT) Date: Fri, 3 May 2024 00:39:17 +0000 In-Reply-To: <20240503003920.1482447-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240503003920.1482447-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240503003920.1482447-2-jthies@google.com> Subject: [PATCH v3 1/4] usb: typec: ucsi: Fix null pointer dereference in trace From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org From: Abhishek Pandit-Subedi ucsi_register_altmode checks IS_ERR on returned pointer and treats NULL as valid. When CONFIG_TYPEC_DP_ALTMODE is not enabled ucsi_register_displayport returns NULL which causese a NULL pointer dereference in trace. Rather than return NULL, call typec_port_register_altmode to register DisplayPort alternate mode as a non-controllable mode when CONFIG_TYPEC_DP_ALTMODE is not enabled. Reviewed-by: Jameson Thies Signed-off-by: Abhishek Pandit-Subedi Reviewed-by: Heikki Krogerus --- Changes in V3: - Returns typec_port_register_altmode call from ucsi_register_displayport when CONFIG_TYPEC_DP_ALTMODE is not enabled. Changes in V2: - Checks for error response from ucsi_register_displayport when registering DisplayPort alternate mode. drivers/usb/typec/ucsi/ucsi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index c4d103db9d0f8..f66224a270bc6 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -496,7 +496,7 @@ ucsi_register_displayport(struct ucsi_connector *con, bool override, int offset, struct typec_altmode_desc *desc) { - return NULL; + return typec_port_register_altmode(con->port, desc); } static inline void From patchwork Fri May 3 00:39: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: 794607 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 A41F315EA2 for ; Fri, 3 May 2024 00:39:47 +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=1714696789; cv=none; b=nQaHCx5U/Fkrsczz+2IzSekjPhJlNG3y9sErjHfWKPbqhi2AWQE0s6ujrSZrJidWsPeg64hH52ZxUdezhTvH7C95NgglbK7R/zd8tibCDBKgP0R/uS2DUqheMes+7gCTmupYzHmexU/NVptM+Y8YsS9asdFGWHzeVTV8GTFB2c0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714696789; c=relaxed/simple; bh=1W6WfWN99WG/pjCYyMD+X7XuHDDI4azbE7UAfj/7jS8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LIidFfxTzLmqOhuabPSMukvyUp6tFdwdIAX3qmZmsbqId7nWJuYsa+vLFK3UsoPkY8asQ9bWWz7mmysJC9/nd2HtcpfGDvCsf9hjsy1QiGfyy/0VXO1BoWrZPwMIs92JYxrsaTEw1lS32GiaQI403N/xDYiFoul16dw1L8Uqmvc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=yA3B7DrP; arc=none smtp.client-ip=209.85.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="yA3B7DrP" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dbe9e13775aso16239252276.1 for ; Thu, 02 May 2024 17:39:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714696786; x=1715301586; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Ev3cYq8jpdJihaDvVJt0iSYbqkUt898jtR/GbVOU2w0=; b=yA3B7DrPU/ieKZ2wOxG9sEQWe0ugOTXMleihyGLewgSyLPBbJXDnUMm4VHzN/6FLvW cC6Pz2vn4oBiK9EsngRZS8q+NeupvXf0ckcOV7ILLCVD4bXVNzO+QwiRqPpw2+WfXmyc px5bNxjpw892MuAFC0Rsrqo2DSEBEhHUHrvDshhMqFutGREbG6CRQVv+wrzotDS0Zevv a2BJMfFTXtsXORwkq1WUYGPKK88QJfvVZHwSLH+B2g8SazPbUMeuDZG3Cl2Se8rrjiSL hk9oQ5mtZ8rcwx5nUz+/NN9kbQ/Fhe+L569wbMp2dnRDCJwMQkZiiowBQpEaDmc7gRoN A48w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714696786; x=1715301586; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ev3cYq8jpdJihaDvVJt0iSYbqkUt898jtR/GbVOU2w0=; b=enoGtxF4B8M2eC7BeGvUSj8CX0mbNB0enygyfvDgx37WwB/VPZzXBdY7a8vgeb9A9d +q8aXjUDo96oUYHZAVykrqHCYSFWprLcqa43gyjkncaYNna59Gsxpqc7mX5YVKAaba1J IWKwWGPRRmT6q4dD+7ji1KvB4UbpmmCb2BaDo7k/T3CX2k9LDtQ0n7cVcsbSf62dpNaa qXeurrPGh4xYUrc727Dirprt4Wo1scWR7Z0bvQdbVCg0fNA7nDdwUYYu/7WKsbfNNxHm gEVD2ejobTuonfVZfS4YO0Bm4zIrV0NbsThj/i5W19IAGod9i5BevNplYFRXPxPL1Fnk IN5g== X-Forwarded-Encrypted: i=1; AJvYcCXRaJC/Pnral/Nm4sP53k7bCRjIxeG5/+3Rp00UfQFJmU2ea+XmNrCv7MLUj8qIY/PiWrNIUyaDKbJXUmc/EUFLWotqoAwnvMj1 X-Gm-Message-State: AOJu0YxvSxUx6a6UjbBpVaGSwvQ4P14B2AOj/F8ibcZ8NhP2w8lF7hoJ 0m8IKdu2KKKgRKV1TlfC0zzlkqJrpoIttRFPszNAD7iCyn51p9rMilLC7U65IszU5QkUsd7WpXR fZQ== X-Google-Smtp-Source: AGHT+IFsDXHVBXexV+q+HUPPZ1A61NbpNAX/YNO61X1Tzqc3GZbiwPa7NnrSWuFsoBHqRKuYYgTm+BG32hw= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a25:26cc:0:b0:de4:e042:eee9 with SMTP id m195-20020a2526cc000000b00de4e042eee9mr383303ybm.6.1714696786732; Thu, 02 May 2024 17:39:46 -0700 (PDT) Date: Fri, 3 May 2024 00:39:18 +0000 In-Reply-To: <20240503003920.1482447-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240503003920.1482447-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240503003920.1482447-3-jthies@google.com> Subject: [PATCH v3 2/4] usb: typec: Update sysfs when setting ops From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org, Benson Leung From: Abhishek Pandit-Subedi When adding altmode ops, update the sysfs group so that visibility is also recalculated. Reviewed-by: Heikki Krogerus Reviewed-by: Benson Leung Reviewed-by: Jameson Thies Signed-off-by: Abhishek Pandit-Subedi --- Changes in V3: - None. Changes in V2: - None. drivers/usb/typec/altmodes/displayport.c | 2 +- drivers/usb/typec/class.c | 18 +++++++++++++++++- drivers/usb/typec/ucsi/displayport.c | 2 +- include/linux/usb/typec.h | 3 +++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/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 3 00:39: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: 794825 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 CA805175AA for ; Fri, 3 May 2024 00:39:50 +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=1714696792; cv=none; b=RIQaPRBMYZ9ZZNV/x/kkzMeut3bdtcq6tIHXLvBs0iYXrgkmhJa+kbEjyXm4zP1hrIPnFtezSRsRgY5YWJ6hsCC4eKWONY5zejrUNLCLdHzl+uZcRRpsN+y9SWtT+P9QkYVIOh+B0MJkRXUWgoZD29hOeKheoBEeaWfwuEEhSJ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714696792; c=relaxed/simple; bh=lPHkPZBn4jDkynyngXHEQSInVHBG5XHwELGRCRAANtY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=cHgMgZZfZqrDXCbwpaK1SIQtQWqvjyqFCXh6Br8bj3yRr2Z8RBYir9okafapjos00uq8+M2fMVJku/t2DsPeee8dW9xCctZ5BMFlBV8292e2+SfDAuQpp8j5svzDPSW3aP5XdqRk5/TYm24O67hfCzutLDjc43rmbsmpPdHTfTA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=tWU1ogX7; arc=none smtp.client-ip=209.85.128.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="tWU1ogX7" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61be23bb01aso93832097b3.2 for ; Thu, 02 May 2024 17:39:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714696790; x=1715301590; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=FSyCNdHT07TNdA8h5B3w30HbKKc0j314DRlrHa4lbZ8=; b=tWU1ogX7s8djMPuEmSXOsGt6v9cox/ILjl6ekn0FX6yO3RLDGzmiq31L90E3DR9GCO E/nBiMIpkZWEx5P0csOFQCxRr+Ch8R39monu7nSmNBO8L0Wx5MAtlJpcEwucrkhBLXH8 W4oXrGacNA0jV4hlmz2U6DstAbsOUM3kZnTrL27kRhZw9WjKFuFRiEK+nzTTQrfHRMCi 7rgUQSeDmENkLVPasem1dwwn9hYC6oMhS72BqvsOv8ytoVHR+g/puqBFFN0mlraa2BPA SsLgwJdQnP5QMR9057iRu1/mQ9ihBmFfzrjGzvXqa4B6z0kuSAZWYqrmwgRpk4/3Dbgw KPRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714696790; x=1715301590; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FSyCNdHT07TNdA8h5B3w30HbKKc0j314DRlrHa4lbZ8=; b=IAB34iCDPqB8jCZ6u5lWMkyHLIbxA/nFEc5Lypcpa7aku3aySEZ+NoiizIHLY7czye r9husJuxvwyX8rxGT0Dhamlx/8ZJ7mIBmWIF2U+OmcK1egBCUM2Vxvw43Yp08D3jfG7j VQxQLXw35M6STv516HmT9zkH7hGyyh7bSpYcZZ20fykSJn74g2e++DfTcvNxX5TZRSys 4igGHuxQdBZWtYnVkcUweg4OMhXTm+R/ek5Pnye9OIea4Urt3hbmEn3wg6uS7TFlmsd7 xVApqzEfN/K0dXXBa2JtGCh5BsjxQTm4Zm1LIahNfvK71gHCUSEC9iR9bLI4PX25hIfd 60HQ== X-Forwarded-Encrypted: i=1; AJvYcCXFSoC+ZE34IGF0URIZMM+S1eYG19edwtN15AkuTgogSWrfXbqnNCWRDZiA2hqPAzv/xZO+M4CA8m2A6f0mnuua9E5fxBAwvKiC X-Gm-Message-State: AOJu0Yz4DkNDd5v4nP2oJEzrfk8uU1iiQSGF2hUe1mQLzm4pDyzv5w1c Uso5lJp0CZUh/uDZIH4d10R65PREqubbYoRX05CKqFmjE3i76qttDFKAFC6lopA7lcijqpvwGfT LGg== X-Google-Smtp-Source: AGHT+IFfQyw8c1TCZjy0mlb3PosEM5hsNooK3RZWKtqyZZTyYTJsB2KvxZTCCk6ZVze/j05u/Xw1etchBYU= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:6902:1146:b0:de4:77ab:5fea with SMTP id p6-20020a056902114600b00de477ab5feamr380431ybu.2.1714696789778; Thu, 02 May 2024 17:39:49 -0700 (PDT) Date: Fri, 3 May 2024 00:39:19 +0000 In-Reply-To: <20240503003920.1482447-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240503003920.1482447-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240503003920.1482447-4-jthies@google.com> Subject: [PATCH v3 3/4] usb: typec: ucsi: Delay alternate mode discovery From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org, Benson Leung Delay the ucsi_check_altmodes task to be inline with surrounding partner tasks. This allows partner, cable and identity discovery to complete before alternate mode registration. With that order, alternate mode discovery can be used to indicate the ucsi driver has completed discovery. Reviewed-by: Heikki Krogerus Reviewed-by: Benson Leung Signed-off-by: Jameson Thies --- Changes in V3: - None. Changes in V2: - None. drivers/usb/typec/ucsi/ucsi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index cb52e7b0a2c5c..bb6e57064513d 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -963,7 +963,7 @@ static void ucsi_pwr_opmode_change(struct ucsi_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 3 00:39: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: 794606 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 9630E1B94F for ; Fri, 3 May 2024 00:39:53 +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=1714696795; cv=none; b=Ckhp9CIu1M7L+OjKJ6gBw9vmeCSZT6dtFaUiLHQ41i1mmiKEXlSqlt6nKlD5sM/pc4cSKAivK24x1VqqxGeRyQe1KWyY20URjHTnKnu4Ie46z0yLw9s6TPfNoczaL7K8Zotic5YJcFbKPthI8a0blRYeH7Rr50dGWTv0L0ufU9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714696795; c=relaxed/simple; bh=qgu2ViOZOk6hT9QT2PkX/dUFnBm0XSHB9y0xx2sW4YM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BsTjyJ6qH2mZz4ll4Rh9utUbOkNh5BZyRUmmqKQlDmJXr92MhZcUTPR28HSNJna+w19b+9lQLA2EpBkoRA2HqJVJ/Q/NXXVz5A9KwQeBAJ/w6K3hMVWiH7vDhhSJLH/YeJ+LpJ69Vq6beiDpz+qMjlGtYLO73p+37LkzUkUh1qo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=h1xL6M+D; arc=none smtp.client-ip=209.85.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="h1xL6M+D" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-de5a378a948so12378334276.2 for ; Thu, 02 May 2024 17:39:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714696793; x=1715301593; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=GHcklqlVkDgPCWtLjA6mJ8uUEpbeCPdZPZls8J1AN9k=; b=h1xL6M+DA8QIWugKiHHdt/J2FOJubjBSjEFNpwHZEbnvkxgnH9rnOrRBjQB3kYnhQU /KcfkNEBsehVD3Poug2wyH7L222UAKxUzKMQYntR2ho4ceCs5WeQHDSlxiqt/9c07pK4 3tqh6299oDBm2dYAmE8rPdLcciUkAfO2J0EhjT0PSnGie6uLqhl0L9krye/8MtZOydQr 3HJiz52Mi1b4L1t8vWY3HY7TKsqqS5AbJ2ouFWakgmNgCurfpX7Jz7nbdy5Peznstbok cwrO5GMHFX3vxOT/NAfJ5TlfVKnEIsmI5BYm+cOIo/QOCkqJVQ0gG204c3Y8h23/iT7N 8fCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714696793; x=1715301593; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GHcklqlVkDgPCWtLjA6mJ8uUEpbeCPdZPZls8J1AN9k=; b=o4GpB/ZWIFOmSc3eeKZcdvyATtKi2GzXg/tkLsnNw0t5r9x62rddO7rsOqI4M1Ca+v pH4dAFLW7a2q+hna9jfVTxTsZ0O2OeOE1Zi8imhAwHTKFA7nSuOmncmy/GwCqREt5MpT sIddEYAm7pVNMlvHkiqeDZonX5QYPAFsxwPdCtdUrPG4BSfFGMk++E6+5rgyIZ327bK9 sbxRfeCBsBwdJqhiXJXlZOLoMyCFr2RU2ax59Rk2z1DSGR0nD+w+LB7Z5fY6BwYT1/Fm Rwy4bu62v57qYMdNlmRAkz8ip7ScAbUUaGVaxrQqf7zAYJaJT80SL9DiDAfM89pBgeH9 w9qQ== X-Forwarded-Encrypted: i=1; AJvYcCUG6luG3auBYzrJc3DVoViNb1qmemydU7tM0/OuHfKCdnLbCUPvTXN9AgjKxf7CTxbpavHSu0nmZIpKQFFZwd5L+XzmBjmIrneZ X-Gm-Message-State: AOJu0YzfwB4oxftpfsDzisfgsgrqYYMFq3AYspNw7dutmmbOVH4XypST PhgYq4r4NTW6qwZRk9jEcX42WjD1vUQ3+HQO88VqhnXotwa9A6qiByhFMqbXXdNn7qdxZ6uE6kp tlA== X-Google-Smtp-Source: AGHT+IGyhxQqfnpdZfpT1wcZoFyJw5400zJ79x/mYwXvqDLeSrFZkOdCg3BGriKoPCxDjgmRotLTtkzJ8gw= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a25:c591:0:b0:de6:1646:58b2 with SMTP id v139-20020a25c591000000b00de6164658b2mr205344ybe.13.1714696792849; Thu, 02 May 2024 17:39:52 -0700 (PDT) Date: Fri, 3 May 2024 00:39:20 +0000 In-Reply-To: <20240503003920.1482447-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240503003920.1482447-1-jthies@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240503003920.1482447-5-jthies@google.com> Subject: [PATCH v3 4/4] usb: typec: ucsi: Always set number of alternate modes From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org, Benson Leung Providing the number of known alternate modes allows user space to determine when device registration has completed. Always register a number of known alternate modes for the partner and cable plug, even when the number of supported alternate modes is 0. Reviewed-by: Heikki Krogerus Reviewed-by: Benson Leung Signed-off-by: Jameson Thies --- Changes in V3: - None. Changes in V2: - None. drivers/usb/typec/ucsi/ucsi.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index bb6e57064513d..52a14bfe4107e 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -812,10 +812,11 @@ static int ucsi_check_altmodes(struct ucsi_connector *con) /* Ignoring the errors in this case. */ if (con->partner_altmode[0]) { num_partner_am = 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; }