Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp213627ybz; Wed, 15 Apr 2020 07:24:59 -0700 (PDT) X-Google-Smtp-Source: APiQypIKj2ubaUMD30WnElAQfGtCdotB/T1DMIIdw7pzF/mc8XZERvCEN0QLRxWxD6Y0kegKFu49 X-Received: by 2002:a50:d5c8:: with SMTP id g8mr25887766edj.370.1586960699411; Wed, 15 Apr 2020 07:24:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586960699; cv=none; d=google.com; s=arc-20160816; b=HeLd1T07VB5H8eHArE5JQhrk7jqhAihCYcBA7e1mQWt95g+loCYOKPBdB/k8mQjcx9 fC93VPh1ZyUH9PmQdGVtjElEN+1pZlU/5NfkcP5YMOg/Loc6SfBE/donsyPu8KMYQnik cSAEbVRprGHf75niI8kyqauSIDH2f2c3FTLSa6TUL+stllJa+G2xj02kgezBN8e8MHfn EUNosyTCmvZWMGVmJ44JJsFtiNTm5sp0fwXbU+8RnGXKz1Z286R8OfQheGZ0gAfZxBD7 Xl6I7ReHeKKzVhk1g01J2NKikFXyWx1k0AaO/yTz8gt3h2/xE6P7QfLk3KiuqVfrnVkV hRtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=xxbRJvmK1dkdxzV18+LiaeJoEhBZWZkg4rYjC5U9q7Q=; b=GZyCfegVaisA7gglo7h5g3YHvq66VFAYHnGJDxNrbRa+JTqV7VbrwsKNK0kNat5hvv Rk4DbAfZxmIKL3U82XrWktbhsJKj4hatTiNuLtecMl+LCz36cQWM+7m9k3dOOyljF17i Wwk4HJA77ZMhGMo+Bqmv9sfzb8PkbQDqWkFiu5/KMi1T9khOEKjslEEHRkup8ZYy3O1K YC7qXgjWlTYsBC+9YQz3Ru+oFl06W5yoAgMqu8Ilc9HW7OcmNoeF+L8ljulB2RKMF0Bm bL8sAO1lErUSZVJZ15i2GA16RVwCwvDgenZEfGm7IOnfTiJ6wCMZSqTU4Vc03iCnDUP/ T1YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=i8ZRofNb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p15si9732238ejj.399.2020.04.15.07.24.34; Wed, 15 Apr 2020 07:24:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=i8ZRofNb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392062AbgDNWoh (ORCPT + 99 others); Tue, 14 Apr 2020 18:44:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729629AbgDNWof (ORCPT ); Tue, 14 Apr 2020 18:44:35 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EAC9C061A0C for ; Tue, 14 Apr 2020 15:44:35 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id 20so7218719qkl.10 for ; Tue, 14 Apr 2020 15:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xxbRJvmK1dkdxzV18+LiaeJoEhBZWZkg4rYjC5U9q7Q=; b=i8ZRofNb0pliu9K5po+RsooXTlGUkyUrzdWtEDbDym464SK3t3VyKXfOVyJPh8PA9a QPlcMWCCigXKVqSj4nS28c3RYDG1w6l3+EvXL4a6y7INZSoaElou5J0ns6idFLJ7OtqU COpt9E5ByXYI0XbfMuAHjsWJ0B790YIDieJhQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xxbRJvmK1dkdxzV18+LiaeJoEhBZWZkg4rYjC5U9q7Q=; b=OwmHNwPUKWIYP5GCWu8JXVOKCLupIlz1JOa9T7X7Mk+oCppl0nH8rgn02HF7PWbQZ7 x+f0w5xU4lgmRy6KHrteT6GdaYOolGu00BDIWutyx+S9+jYh/FUlcZ0uYOy0cZS0QzF7 sTFY9VRkthrSsiqwpjW/FINzlyCIkR0JUCwsoS49U8vef902cdrURHJtPJPJYjgniVuW Nqt3JxOzLIipfkr3YBAq5d9PHGJV/p1FqHPUWjxnS3v5yNUaitT6v8NAUz4Lu0sVBGi0 bdVSGfWh2B5lqkbAbQDGQ//kREgPirfY8BJEuQsdUuRSfamIdaFF/Yd45eNPdz81V/Zm Rlvg== X-Gm-Message-State: AGi0PuY/t+S98rMSZWW1fkq5y5+2WiEjfOZjrysWBIie49BuLnJr0b4w 4Hkvr6S4w+jPbES8SEGtjmViIRNngOIWwISl4nY+kw== X-Received: by 2002:ae9:dd02:: with SMTP id r2mr21859004qkf.180.1586904271480; Tue, 14 Apr 2020 15:44:31 -0700 (PDT) MIME-Version: 1.0 References: <20200410002316.202107-1-pmalani@chromium.org> <20200410002316.202107-4-pmalani@chromium.org> <025802e6-207c-305a-8146-3c07a3f36bb4@collabora.com> In-Reply-To: <025802e6-207c-305a-8146-3c07a3f36bb4@collabora.com> From: Prashant Malani Date: Tue, 14 Apr 2020 15:44:19 -0700 Message-ID: Subject: Re: [PATCH v3 3/3] platform/chrome: typec: Register port partner To: Enric Balletbo i Serra Cc: Linux Kernel Mailing List , Heikki Krogerus , Jon Flatley , Benson Leung , Guenter Roeck Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks for the review Enric, On Tue, Apr 14, 2020 at 7:08 AM Enric Balletbo i Serra wrote: > > Hi Prashant, > > Thank you for your patch. > > On 10/4/20 2:23, Prashant Malani wrote: > > Register (and unregister) the port partner when a connect (and > > disconnect) is detected. > > > > Co-developed-by: Jon Flatley > > Signed-off-by: Prashant Malani > > --- > > > > Changes in v3: > > - No changes. > > > > Changes in v2: > > - Fixed error pointer return value. > > > > drivers/platform/chrome/cros_ec_typec.c | 48 +++++++++++++++++++++++++ > > 1 file changed, 48 insertions(+) > > > > diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c > > index 56ded09a60ffb..304e0b20f279b 100644 > > --- a/drivers/platform/chrome/cros_ec_typec.c > > +++ b/drivers/platform/chrome/cros_ec_typec.c > > @@ -22,6 +22,9 @@ struct cros_typec_port { > > struct typec_port *port; > > /* Initial capabilities for the port. */ > > struct typec_capability caps; > > + struct typec_partner *partner; > > + /* Port partner PD identity info. */ > > + struct usb_pd_identity p_identity; > > }; > > > > /* Platform-specific data for the Chrome OS EC Type C controller. */ > > @@ -190,6 +193,30 @@ static int cros_typec_ec_command(struct cros_typec_data *typec, > > return ret; > > } > > > > +static int cros_typec_add_partner(struct cros_typec_data *typec, int port_num, > > + bool pd_en) > > +{ > > + struct cros_typec_port *port = typec->ports[port_num]; > > + struct typec_partner_desc p_desc = { > > + .usb_pd = pd_en, > > + }; > > + int ret = 0; > > + > > + /* > > + * Fill an initial PD identity, which will then be updated with info > > + * from the EC. > > + */ > > + p_desc.identity = &port->p_identity; > > + > > + port->partner = typec_register_partner(port->port, &p_desc); > > + if (IS_ERR_OR_NULL(port->partner)) { > > + ret = PTR_ERR(port->partner); > > If you're checking for IS_ERR_OR_NULL that means that port->partner can be NULL, > so PTR_ERR(NULL) is 0 returning something that you don't really want. > > But looking at the typec_register_partner, NULL is not an option as returns a > handle to the partner on success or ERR_PTR on failure. So, the code should just do: > > if (IS_ERR(port->partner)) > return PTR_ERR(port->partner); Will update the patch to do this on the next version, thanks. > > And AFAICS you don't need to set port->partner to NULL. > > Can you double check this? I think we will need it, since we check for it in cros_typec_set_port_params_v1() to avoid double registration of a partner: + /* Register/remove partners when a connect/disconnect occurs. */ + if (resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED) { + if (typec->ports[port_num]->partner) + return; So if it is not set to NULL on error earlier, the registration won't take place here (in case another PD notification comes in while the PD_CTRL_RESP_ENABLED_CONNECTED bit is still set). Kindly correct me if this understanding is incorrect. Best regards, -Prashant > > Thanks, > Enric > > > + port->partner = NULL; > > + } > > + > > + return ret; > > +} > > + > > static void cros_typec_set_port_params_v0(struct cros_typec_data *typec, > > int port_num, struct ec_response_usb_pd_control *resp) > > { > > @@ -212,6 +239,8 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec, > > { > > struct typec_port *port = typec->ports[port_num]->port; > > enum typec_orientation polarity; > > + bool pd_en; > > + int ret; > > > > if (!(resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED)) > > polarity = TYPEC_ORIENTATION_NONE; > > @@ -226,6 +255,25 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec, > > TYPEC_SOURCE : TYPEC_SINK); > > typec_set_vconn_role(port, resp->role & PD_CTRL_RESP_ROLE_VCONN ? > > TYPEC_SOURCE : TYPEC_SINK); > > + > > + /* Register/remove partners when a connect/disconnect occurs. */ > > + if (resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED) { > > + if (typec->ports[port_num]->partner) > > + return; > > + > > + pd_en = resp->enabled & PD_CTRL_RESP_ENABLED_PD_CAPABLE; > > + ret = cros_typec_add_partner(typec, port_num, pd_en); > > + if (!ret) > > + dev_warn(typec->dev, > > + "Failed to register partner on port: %d\n", > > + port_num); > > + } else { > > + if (!typec->ports[port_num]->partner) > > + return; > > + > > + typec_unregister_partner(typec->ports[port_num]->partner); > > + typec->ports[port_num]->partner = NULL; > > + } > > } > > > > static int cros_typec_port_update(struct cros_typec_data *typec, int port_num) > >