From patchwork Fri Jun 23 15:10:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Tso X-Patchwork-Id: 13290782 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 9E03AC001B3 for ; Fri, 23 Jun 2023 15:11:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232507AbjFWPLs (ORCPT ); Fri, 23 Jun 2023 11:11:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232515AbjFWPLW (ORCPT ); Fri, 23 Jun 2023 11:11:22 -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 A6713270D for ; Fri, 23 Jun 2023 08:10:57 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-57059e6f9c7so20704037b3.0 for ; Fri, 23 Jun 2023 08:10:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687533048; x=1690125048; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=T40jLz8j0sR+fx+XMBB91BKek6keV7mMBCBlptKA/U8=; b=GnnRHZDe78YBLKXJsdQtn7wz3MkeuX+BclwIgqwJFM92Ezl8Gmz/QpSXK/IrbzRumx UCPt21Pys2hdv88fERmfDTCmDXa7lquNN3A9HTzsh6jP/LxNjSQ9QBmcAzFlvJIUL//R tiFvjot++QA5yrakJedMekfntctSIgo7XdYLzDffzizBo6h79Uqpu7Xzaz0EVaejgAx7 OkB0v2UAeKvPpJTUWk0PGQN2kQuOKxGchi+pha+AvghMsYsGT4xnH4eBiEJm1VHaqg6l r1KGooFP6ySFnWuxCIHVNPsGFbzcv5Z6j6muXmoeq48xqlx5avSulHon1VMKeI6xhRu8 O4jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687533048; x=1690125048; 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=T40jLz8j0sR+fx+XMBB91BKek6keV7mMBCBlptKA/U8=; b=YM+8056XTgXZWkuPZRXx3KV003FIjktSdIPoR8q8SmeavAydfraHZImzkf6zEUvkZt vZIqpO0T71SOYhaVMFPi5yG7DE8l1KCVRdwyAih88bSoVc/L8BInf47WNrvaHa+0FMpP 7JrqjfbXcdfbpcg1V9kqJCN99/ogF/5VoJahMlB9zsBI/i48diFz//40R6MAq9sUZJwl AIMoLZjbEqDQFS1cTC8lF8ZuHhI62/dZiZk99hPnltQeHnI1L8Qm69nei/drHYD6cLDF Q2fU/8e/T1DM2NgqAQkRMXpnuGOeWsFQl40oStVbj2aUI83INPVssYtOp1ugaxHZtdJx S7BA== X-Gm-Message-State: AC+VfDzB8/iofzSD9Dm3w4eMxNnwm+n6t8pB6f8qoh3PbxIZl2u2EDbr nvdyHDtlX7WYnia+IuEc9PqzUHRDc1LQ X-Google-Smtp-Source: ACHHUZ6xY5RzJ8jDAd/nnL1MFEmFnRw+b+2byYBxQxlp3osCgR5yLOzm7tYWrL9Eq5BCrSo55OJeCuPi3wlP X-Received: from kyletso-p620lin01.ntc.corp.google.com ([2401:fa00:fc:202:5d47:84a:2819:bba4]) (user=kyletso job=sendgmr) by 2002:a05:690c:b92:b0:565:8b2e:b324 with SMTP id ck18-20020a05690c0b9200b005658b2eb324mr14438059ywb.3.1687533047959; Fri, 23 Jun 2023 08:10:47 -0700 (PDT) Date: Fri, 23 Jun 2023 23:10:34 +0800 In-Reply-To: <20230623151036.3955013-1-kyletso@google.com> Mime-Version: 1.0 References: <20230623151036.3955013-1-kyletso@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230623151036.3955013-2-kyletso@google.com> Subject: [PATCH v2 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 , stable@vger.kernel.org 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") Cc: stable@vger.kernel.org Signed-off-by: Kyle Tso Acked-by: Heikki Krogerus --- update v2: - Add "Cc: stable@vger.kernel.org" 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 Fri Jun 23 15:10:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Tso X-Patchwork-Id: 13290783 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 93367EB64D7 for ; Fri, 23 Jun 2023 15:12:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232081AbjFWPMh (ORCPT ); Fri, 23 Jun 2023 11:12:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232421AbjFWPL0 (ORCPT ); Fri, 23 Jun 2023 11:11:26 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E785630CA for ; Fri, 23 Jun 2023 08:11:00 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-c005a8ca4d9so1191253276.3 for ; Fri, 23 Jun 2023 08:11:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687533051; x=1690125051; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=cWOe4G+wpmnb5gd06s9NrCHMZgll/w3qfqnd7bhy3bc=; b=Jj/yxG+yIyl39+9PshdtRNnQl83V3MTYlDVNl2fs3iI/PzAP7RW+vmUWf0Jq5kskqI MAqHQHyV+XcyIU9ROSTPZNbAKeZgucUc5lJA+Ow7aq/A3kQADTei3VqyDa2QfhEXO7Fb Vxzr+Hk82hDzH1ANycuG1Xy1obuPKlPXDgzYTLk9o3FL51Vxv2xG8PC/KVsmp9iXTCei 7vaUP0erVNLILVods2i8ukaat4uzp0cG1UyEq2usWryDXM9FjjY/i/XIX85UAKX+lVIL BxRL/43kV2S06krC83sjJwXjNCJcIH6hGMkQznNvpQGS8xagGSm86mf6Hcy91QxwV64z lmfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687533051; x=1690125051; 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=cWOe4G+wpmnb5gd06s9NrCHMZgll/w3qfqnd7bhy3bc=; b=Sl4pUObaJluL+0ljvczIx16ywa6Zpw8/C4NiwbCmX61q+n22jxH+Nx/ygRDh8Ofs7w wGVLgGXC27PhsVkQezRku2rdIXWVoAtYOAO4kbpdhBtlbcd3Ectj2gERS9IcpMqJBMcE n17zhDJCktfuDLDLXG63hmOgu3PTVC3U0fd8IiJPWw0vyBUCDCPrmVpPPIgZSoU2rw3F FnzHNhwnDbODsClgkfjTeFFQ2x6see7T9sXeLdFenRuAJCkL2UDb7V5rNUizy8p2+uL2 PEhtIQqU29fS/pESL+YmTtlxEgktYBWnALY+vCwq6SNWzMmYFDQXNAndDI4sxDF2vwwD 75bg== X-Gm-Message-State: AC+VfDwRXDwHVCJRv0+tCwVrUIhTXmMemCeH9ETH8MJYGvSzUWUtFEy9 7l+SZDBTcfFo3at75sgq5uX/WhBgi5Jy X-Google-Smtp-Source: ACHHUZ4gPafdv3C+UoOxNcOU9t72cQxJhDlpjLvIlSWm84SE09aIWG7IELM5dB5Eknx0Q3cgRbrtrnpXFHvV X-Received: from kyletso-p620lin01.ntc.corp.google.com ([2401:fa00:fc:202:5d47:84a:2819:bba4]) (user=kyletso job=sendgmr) by 2002:a25:6989:0:b0:ba8:9096:df50 with SMTP id e131-20020a256989000000b00ba89096df50mr3687174ybc.9.1687533051741; Fri, 23 Jun 2023 08:10:51 -0700 (PDT) Date: Fri, 23 Jun 2023 23:10:35 +0800 In-Reply-To: <20230623151036.3955013-1-kyletso@google.com> Mime-Version: 1.0 References: <20230623151036.3955013-1-kyletso@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230623151036.3955013-3-kyletso@google.com> Subject: [PATCH v2 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 , stable@vger.kernel.org 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") Cc: stable@vger.kernel.org Signed-off-by: Kyle Tso Acked-by: Heikki Krogerus --- Update v2: - Add "Cc: stable@vger.kernel.org" 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 Fri Jun 23 15:10:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Tso X-Patchwork-Id: 13290784 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 8B20EC001B0 for ; Fri, 23 Jun 2023 15:12:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232449AbjFWPMl (ORCPT ); Fri, 23 Jun 2023 11:12:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232446AbjFWPL2 (ORCPT ); Fri, 23 Jun 2023 11:11:28 -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 D986E30D5 for ; Fri, 23 Jun 2023 08:11:03 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-56fffdea2d0so10663697b3.1 for ; Fri, 23 Jun 2023 08:11:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687533055; x=1690125055; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Z6FSiQisg0W7MOfyBIAiPdkeELt112zv/p4uKtG83Y0=; b=uLzCMJTw7jDxS6vNull8bIpFUWN/rBWTBCpL4cvA+4bgV96XBXkEvusTIVrUSsTbE/ 6QZb64qW2UIzBrT10hhQbkhpCO0MdVvuJn1UIUklgJYZOBpX/RRgP6cvbZsti/Q0pV9T lSuGOa6+dLJZq8Ih5W7yX+a26+/n+Js77Cgrr7TOaKfktmdBkQvKGRlLRgCd+RIMsXpa bwHrHYdfMMbHhZ3EODuiAbpfX4gW8gJ5w3+4JlNPz7dCwySWpxcB1P3sM0Dp1y1oJ4Ib UsCx9khVhwwPqXsEHrsaRx385tz6R5Vr1rc1mKdoaDeXckjssRzo4gi88skKkFdc6hFG N/iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687533055; x=1690125055; 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=Z6FSiQisg0W7MOfyBIAiPdkeELt112zv/p4uKtG83Y0=; b=iD8FOG8sxqdh8A2U1HZ/Wv+Vhvb48mM1W60Ud8964J5rlriJ8nxF+YopKRMpRxKvg5 aBJUllgzJf4Y62FurmLomZKH3AIch2oO459hmlKoOMQZ3h3R2k2biabVCX3NRgrf3+Et mSSD8NU8kwRKr2PEjcGvIkfL/X30EPcV79jkzsSZbkkp63xsJnO2Zv/bszVzVjrxZmP2 ku4Hpgy1rKACWC8rT1+BkzD0q2CkC+IZBLu68O6WRnrGIGyn9cAZLPrihApPaTtwzsjZ 1ecZBGtTtG5VirXy2l6srXeCFTKBeilNrxPq/ZE+lwi5r1hf9JnfX6ap8h6FMp/aKRI1 T5AQ== X-Gm-Message-State: AC+VfDzHmsa/u/J0zEMVnR670/dS8QXos4NGGzzHuezwWStTug+qcefM ELcFNbvcnRKAvEaIaWSmNPHBy2qLkdtz X-Google-Smtp-Source: ACHHUZ5Hc+kLLEtZILQ4Wma4p08PO6/FbwCQ/44hQJQvk3dSaS/TSPaISlSEc+0hqXQbINbYXQj+bHrZ0eR3 X-Received: from kyletso-p620lin01.ntc.corp.google.com ([2401:fa00:fc:202:5d47:84a:2819:bba4]) (user=kyletso job=sendgmr) by 2002:a81:af11:0:b0:573:87b9:7ee9 with SMTP id n17-20020a81af11000000b0057387b97ee9mr5097095ywh.4.1687533055500; Fri, 23 Jun 2023 08:10:55 -0700 (PDT) Date: Fri, 23 Jun 2023 23:10:36 +0800 In-Reply-To: <20230623151036.3955013-1-kyletso@google.com> Mime-Version: 1.0 References: <20230623151036.3955013-1-kyletso@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230623151036.3955013-4-kyletso@google.com> Subject: [PATCH v2 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 , stable@vger.kernel.org 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") Cc: stable@vger.kernel.org Signed-off-by: Kyle Tso Acked-by: Heikki Krogerus --- Update v2: - Add "Cc: stable@vger.kernel.org" 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';