From patchwork Thu Jun 22 15:04:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Tso X-Patchwork-Id: 696219 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6A4AC001DD for ; Thu, 22 Jun 2023 15:05:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232284AbjFVPFk (ORCPT ); Thu, 22 Jun 2023 11:05:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232267AbjFVPEx (ORCPT ); Thu, 22 Jun 2023 11:04:53 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FD03199D for ; Thu, 22 Jun 2023 08:04:47 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-573a92296c7so24765527b3.1 for ; Thu, 22 Jun 2023 08:04:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687446287; x=1690038287; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6msxjfGSl7/M9KTU2PiCryY5ju9+3DU82TDMWlxq2Cw=; b=u81k2ossffJeZlh2McBdWUMdmw5bSOOZ9+IZJXixIWqXinaFFtEvowwVnYqexAoXBk FKSwthoF4lqXQhJRcE64mXqPCsSfEoloq1p1ijm5if8G9ZnZaMusJzj7ZUX70vpiCBvR aaWr+3CjEpVy9JX88po4lTxc1QERRtodUS0jbPkfOfOv4agfTfCY86oMhxjCxZligekm a54R+an15LBK9YA1IQyYvZclaXk2HDro/gsGvRKfpjVClBdYSJVyZEOs21cFoK9zzuqU ZPHedBZgEBxmh6sT0+4z3YgTW5br1ZoGph3VNpo1KUejbQyzKDejqDJSmFZDlvoffBgL QAQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687446287; x=1690038287; 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=6msxjfGSl7/M9KTU2PiCryY5ju9+3DU82TDMWlxq2Cw=; b=GsArx+b+OtYfY9CNGBt3tE5G6kS+8Hwx6/kIBeWoZtQjuTdNj0JNJiCp+UlGEb4yPi 5f1illacpfh899KD0w8lgvkofqgdNg92l05jW+wgE3HxR4bGzrmxAHkQYA+BEVolWlWO jTdTItmXlOrEZoUJZlndkbB2XWsJZ8mv9nnum7hBi9P+g680Tzta5CfbQXgjJM723MAw JBo43J7ZB2wwbxBOHHa6QlQmV84RUHpwIjz5L8bLlYCfreP27LKJRMbXT0gol5wR942B eXJgHCksVwYZFKaUKgoejERjtGw+qd+LFgiCUR3tRVAgi4sa5vq2VBflcZ2bIAoGKVgL AKrg== X-Gm-Message-State: AC+VfDwFQ8qfe8eCL6YsGVzZOnX2oHtJa5F3uVUO0m/cLSuwOp6TU9vi GM65vr/PtNjJO5qXWZU25dMNn4XyPiwn X-Google-Smtp-Source: ACHHUZ7Xn8kcYYlAhb46y9g1ZnLqOGI6n5PbyVRrSXY2TCNhq9gefZuSqICs3dtSotmutG2sKqA5u5vFj3/l X-Received: from kyletso-p620lin01.ntc.corp.google.com ([2401:fa00:fc:202:b1ba:4098:b043:5e54]) (user=kyletso job=sendgmr) by 2002:a81:e24a:0:b0:56d:2abf:f0c with SMTP id z10-20020a81e24a000000b0056d2abf0f0cmr7755784ywl.10.1687446286806; Thu, 22 Jun 2023 08:04:46 -0700 (PDT) Date: Thu, 22 Jun 2023 23:04:21 +0800 In-Reply-To: <20230622150423.3726894-1-kyletso@google.com> Mime-Version: 1.0 References: <20230622150423.3726894-1-kyletso@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230622150423.3726894-2-kyletso@google.com> Subject: [PATCH 1/3] usb: typec: Set port->pd before adding device for typec_port From: Kyle Tso To: heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org Cc: badhri@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kyle Tso Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When calling device_add in the registration of typec_port, it will do the NULL check on usb_power_delivery handle in typec_port for the visibility of the device attributes. It is always NULL because port->pd is set in typec_port_set_usb_power_delivery which is later than the device_add call. Set port->pd before device_add and only link the device after that. Fixes: a7cff92f0635 ("usb: typec: USB Power Delivery helpers for ports and partners") Signed-off-by: Kyle Tso --- drivers/usb/typec/class.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index faa184ae3dac..3b30948bf4b0 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -2288,6 +2288,8 @@ struct typec_port *typec_register_port(struct device *parent, return ERR_PTR(ret); } + port->pd = cap->pd; + ret = device_add(&port->dev); if (ret) { dev_err(parent, "failed to register port (%d)\n", ret); @@ -2295,7 +2297,7 @@ struct typec_port *typec_register_port(struct device *parent, return ERR_PTR(ret); } - ret = typec_port_set_usb_power_delivery(port, cap->pd); + ret = usb_power_delivery_link_device(port->pd, &port->dev); if (ret) { dev_err(&port->dev, "failed to link pd\n"); device_unregister(&port->dev); From patchwork Thu Jun 22 15:04:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Tso X-Patchwork-Id: 695200 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84E38EB64DC for ; Thu, 22 Jun 2023 15:05:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232272AbjFVPFj (ORCPT ); Thu, 22 Jun 2023 11:05:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232328AbjFVPE5 (ORCPT ); Thu, 22 Jun 2023 11:04:57 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F13A1FE1 for ; Thu, 22 Jun 2023 08:04:51 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-57059e6f9c7so15651087b3.0 for ; Thu, 22 Jun 2023 08:04:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687446290; x=1690038290; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=vZO0bLWsCUzvZiCFoSnFZwrtuz12yaBesFgNlWXPmT0=; b=O4AQJntmNrrzpA/osOkPU0d1y9/b3wfMewtlOXTOG5Pkz+psJggS/9wWf7apbcG6as cAnVTf9k+WP71BQEkHdZKkIv5GfJSWEm0zMljR8RE1LB5GBR4fbULYo6KFxYNwdDyWgy s5i3fr9/Km/GH6EjoblamoRcI6pmodeaHt6tKJweOD1zPHK/tceQ15xB5ThAPsg43Ekl KicSBo4d4GlRP7uFMqDKUsI5n3Ll1dgpa8WgqvyxbJxTIGdBW87/8XR3l2pLgSsv7T8/ D4Vsy9L8rsjqxAj9BuIASWaBIkOJWN/9I0o2Qadw0R4/wOwO6mtYgRhUz/srI1lEL9RO cgFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687446290; x=1690038290; 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=vZO0bLWsCUzvZiCFoSnFZwrtuz12yaBesFgNlWXPmT0=; b=i2izXD+WxKb5qv+stUzdfQymIC6W1aQfr5vl3lhTDcIjm5Ljhc29X2x/anR5DeS6ja RFfs+X6D6soDXQM7QbmamgbkIpQ2QVJ//Ps0cAG3Pb+cdBPjlJ8/pORu9PSbr/dksyPs Br0faEJFYFj7hX2e5dFiHShQcYM+WFdqvvcNGoPx+4v46pWLIrrhkPOmd+V4F+YriCGh 0/OuJYQuLG9zjN6y4Dw1nv/CmamjAPJl78RMyO0wFNZyegcip2ygAxsE8agE0FPORrGs ImSCxP/fw7jSCb0iPg9yUkOTfwDaYoHZKbtYFX4etaKLKVAZQSac8k9w+59C5TO+N8xX IKCw== X-Gm-Message-State: AC+VfDyihKNo+0OcKTCTgSWcnH0Sp0411W2T1gud5c5PIJ7x+h+khfQ9 P0OgZhOT66NZJC2b3J9atgJvs7eUHjPr X-Google-Smtp-Source: ACHHUZ7eMdBNde25i7j4MRD+O/BRZV9gU7ydeOols5A25Lz1pht25onjLAZ9R30ou8GxtYCBOlpV+PS8UyTb X-Received: from kyletso-p620lin01.ntc.corp.google.com ([2401:fa00:fc:202:b1ba:4098:b043:5e54]) (user=kyletso job=sendgmr) by 2002:a05:690c:b92:b0:565:8b2e:b324 with SMTP id ck18-20020a05690c0b9200b005658b2eb324mr12338278ywb.3.1687446290808; Thu, 22 Jun 2023 08:04:50 -0700 (PDT) Date: Thu, 22 Jun 2023 23:04:22 +0800 In-Reply-To: <20230622150423.3726894-1-kyletso@google.com> Mime-Version: 1.0 References: <20230622150423.3726894-1-kyletso@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230622150423.3726894-3-kyletso@google.com> Subject: [PATCH 2/3] usb: typec: Iterate pds array when showing the pd list From: Kyle Tso To: heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org Cc: badhri@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kyle Tso Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The pointers of each usb_power_delivery handles are stored in "pds" array returned from the pd_get ops but not in the adjacent memory calculated from "pd". Get the handles from "pds" array directly instead of deriving them from "pd". Fixes: a7cff92f0635 ("usb: typec: USB Power Delivery helpers for ports and partners") Signed-off-by: Kyle Tso --- drivers/usb/typec/class.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 3b30948bf4b0..e7312295f8c9 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -1277,8 +1277,7 @@ static ssize_t select_usb_power_delivery_show(struct device *dev, { struct typec_port *port = to_typec_port(dev); struct usb_power_delivery **pds; - struct usb_power_delivery *pd; - int ret = 0; + int i, ret = 0; if (!port->ops || !port->ops->pd_get) return -EOPNOTSUPP; @@ -1287,11 +1286,11 @@ static ssize_t select_usb_power_delivery_show(struct device *dev, if (!pds) return 0; - for (pd = pds[0]; pd; pd++) { - if (pd == port->pd) - ret += sysfs_emit(buf + ret, "[%s] ", dev_name(&pd->dev)); + for (i = 0; pds[i]; i++) { + if (pds[i] == port->pd) + ret += sysfs_emit(buf + ret, "[%s] ", dev_name(&pds[i]->dev)); else - ret += sysfs_emit(buf + ret, "%s ", dev_name(&pd->dev)); + ret += sysfs_emit(buf + ret, "%s ", dev_name(&pds[i]->dev)); } buf[ret - 1] = '\n'; From patchwork Thu Jun 22 15:04:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Tso X-Patchwork-Id: 696220 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D397AEB64DB for ; Thu, 22 Jun 2023 15:05:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232237AbjFVPFg (ORCPT ); Thu, 22 Jun 2023 11:05:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232376AbjFVPFC (ORCPT ); Thu, 22 Jun 2023 11:05:02 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1602AE7E for ; Thu, 22 Jun 2023 08:04:55 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-565a33c35b1so88477287b3.0 for ; Thu, 22 Jun 2023 08:04:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687446294; x=1690038294; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6HP4+YvUJVAPeSikWLLN9lmrDsE6bkUx0eYDaGV1KtY=; b=KVoocYmnlhWTcw1lpk8n+2IXXtKbUtQpLc1W6m42G16fgk/46hQ24ls0r0EQJLHur8 yi/2LxA0+duj7u/xyHLD2V+A9au+OpYQ5X5LOBaK7Eus9D3VJSr++d3qxu5VPTKcnYLd KsVUSfEZTrtYiWxSoHnHUbjM+rBdnkc/8HdJ7hYuGnau5poq/Xk/4LUpIXMeDp/4/5f4 P3lmmusCUD0TDns0/jFuTafZF1gDDAsvnosK9q/2mMD4M0M11llif0owUxVojq9vx+kX 5kmYk5e+yeRWtOKTvav3QYIHC3ZzjYLPL7f+yvmDTFP621TuKCGjiYHqAqskSEgoK9D7 4KAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687446294; x=1690038294; 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=6HP4+YvUJVAPeSikWLLN9lmrDsE6bkUx0eYDaGV1KtY=; b=DN7Km4yBBHPd2Hcgidty8em1eSdUU68RE38uhEcwjMtm8JAJq61H3VH7aBsZVhpOKV 2idlKG8GfFIlVk96nkmQT+TExIdAiHbhcCwJNcxY87+P1C3svuKpQgZfQfa4UQGd9Y2a xdgpX9LAiI5qeg2NX00zH5beOtqIxS/fEdl92UTiVl8ZtX084wpTc0Q9Cv7LJ55zj8FW cIR6BBoxyXfKYuVSgCB/T/28x1LcCj28RBsKS+rizO+rDBpwVQ/6z5rNcbIAyo5CypyE u/VWlx0ZFqfoP9SZWYmtLM3VSjsi7TfKnGu3l6dv+/RHIvgnCqYxjROjwzpE7lpF5K1P beYA== X-Gm-Message-State: AC+VfDy9wCJwO5KXgqqmxFovnlxktIJlE8DvxyNhqOLqUZ/DdmywGVfF 0+c5wewdDfi4e5PrIVSKOuw6crYguEL3 X-Google-Smtp-Source: ACHHUZ496dL12nzIYLBFIu7BX5QCmCLSyZn7xI5fg8prNXpCnYIZvjhBPUphoZKuZ//HYYoKQleHSuToMCWm X-Received: from kyletso-p620lin01.ntc.corp.google.com ([2401:fa00:fc:202:b1ba:4098:b043:5e54]) (user=kyletso job=sendgmr) by 2002:a81:4318:0:b0:565:9bee:22e0 with SMTP id q24-20020a814318000000b005659bee22e0mr7091813ywa.0.1687446294377; Thu, 22 Jun 2023 08:04:54 -0700 (PDT) Date: Thu, 22 Jun 2023 23:04:23 +0800 In-Reply-To: <20230622150423.3726894-1-kyletso@google.com> Mime-Version: 1.0 References: <20230622150423.3726894-1-kyletso@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230622150423.3726894-4-kyletso@google.com> Subject: [PATCH 3/3] usb: typec: Use sysfs_emit_at when concatenating the string From: Kyle Tso To: heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org Cc: badhri@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kyle Tso Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The buffer address used in sysfs_emit should be aligned to PAGE_SIZE. Use sysfs_emit_at instead to offset the buffer. Fixes: a7cff92f0635 ("usb: typec: USB Power Delivery helpers for ports and partners") Signed-off-by: Kyle Tso --- drivers/usb/typec/class.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index e7312295f8c9..9c1dbf3c00e0 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -1288,9 +1288,9 @@ static ssize_t select_usb_power_delivery_show(struct device *dev, for (i = 0; pds[i]; i++) { if (pds[i] == port->pd) - ret += sysfs_emit(buf + ret, "[%s] ", dev_name(&pds[i]->dev)); + ret += sysfs_emit_at(buf, ret, "[%s] ", dev_name(&pds[i]->dev)); else - ret += sysfs_emit(buf + ret, "%s ", dev_name(&pds[i]->dev)); + ret += sysfs_emit_at(buf, ret, "%s ", dev_name(&pds[i]->dev)); } buf[ret - 1] = '\n';