Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1926829ybh; Sun, 15 Mar 2020 14:42:28 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuAVwocmPfAe0WBc6KUZNxOUkNiXq/75+XmVBBQ9cQSXs+FVXmxDfA8/vdcf89fEEhaiodF X-Received: by 2002:aca:d882:: with SMTP id p124mr15226312oig.178.1584308548651; Sun, 15 Mar 2020 14:42:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584308548; cv=none; d=google.com; s=arc-20160816; b=bx9lOiAwJe2D0Pdm1uHd9d/bsOfVDkXcEZwEp2gDes9jrEhiepAUC97lqS3+fA9mCG fb6M59DNslFsnBGlPapjgbng95AiffZY42Y/vNaWugbZl9CyPLsXNpJl+qbzJBpNOtTq uweRvK8ITC+weeBp98PjkdqxzBMHstTQ/f1SExToUEjgYxketM1YdQLEx1D5KKN5s5Ib ncMBarcr47hET6oYtMBGJzBIDVle1d/91ToiOccQWARKKIx49KE4ExWfHQG7xuSXb63G k0ZgP3oWy0tcGjhgZJ5ipaE/sVTXuWDrTTAEK3qEKSvR31SxWneWTCuYfBDMOiYnRBig nWfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=mC8CXXtUqsLPv7Yc0qSPZwh0pSfdpja7KBYMCXDnZPE=; b=VxHQFkAVtJk5ni1Xtx/1NvfY5B1vYoTciFdi+ZW8Sb/4Mj0S7kV7KXZzP15mWXTezt hLftOEHYvy2SOUPnYC9bBVEYMMImbysZXcJYdaQZzAhvtXLTNxsMdjXwWrKJ0MYW27ZP Xm68GZB9UgjRXqQk7zP4JvcgL9clBgL58lhjc0UU3kp5/guq+AcC7eJnQ9ibZeJH8zbt 6XBeyPpRHuDsGrenQD5bQ4zZPAIg3q5nBZqhUhei5B8KYNND7FAUY40J0jTQD5E0caDT zzhgQEdrBizwiZyQN9pz0r6NYVkIPs80RvO+BKXw5qPT8s6iaUL6m9mtiNP5Zy6pMUgV P7PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=T7oracMy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id a15si8932720otf.83.2020.03.15.14.42.16; Sun, 15 Mar 2020 14:42:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=T7oracMy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1729213AbgCOVlW (ORCPT + 99 others); Sun, 15 Mar 2020 17:41:22 -0400 Received: from mail-pj1-f66.google.com ([209.85.216.66]:55611 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729166AbgCOVlW (ORCPT ); Sun, 15 Mar 2020 17:41:22 -0400 Received: by mail-pj1-f66.google.com with SMTP id mj6so6953049pjb.5 for ; Sun, 15 Mar 2020 14:41:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=mC8CXXtUqsLPv7Yc0qSPZwh0pSfdpja7KBYMCXDnZPE=; b=T7oracMyfCuyfTHRyqGd3oJ2PZaRyWpwDr9crQ6CP8QTO3JpTa8SoaB2JRsu5D97+4 2yiLqqsVast/yg5zHHp9NIi5p21jhrj2C7rB6Rqkfpi1FPKWEgFqcUk5+fvxxbywzv7y sXgNm8WD9+r1B/2dFY0lyYomA1Z/b9qNLLj3A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=mC8CXXtUqsLPv7Yc0qSPZwh0pSfdpja7KBYMCXDnZPE=; b=RG3nXOqbdkw2bXqmg4N4f5/RUh83nKx1NLKPm19kxTAbJuNKwpQjOooZVGA7stu/cl 1kyZ2ABK5MnejleJvxkE9b86ORWXaoW1kkzjk9GYekWGSX5GxnczF9EZ7tYUjIDHngP4 bU8R+GaD/NATXJQKubp7Gsd8KxsLiIyUawDL96kDlIlrsQLs2woC3kKGCygMf1aUPscT oUqnnAHChRVssVlRPCXv48Lh+Dr+6hiNWaY2ijNuPdl43sI+fUUBq0Fm5Ue+vDy4HbQL Kv099rB0DpKH1g+bdw8/JC4DI+IyPTVteWAK0DUVGtGr4SQ0BbL/gr0V8KKqqUM+1ZM2 unug== X-Gm-Message-State: ANhLgQ3pAKjYvs0VDgTSaO5e4ScgIXt+ZIl+4UlML25FlvqNNCnezNmh yQ+y/7+m7jG8kcB3DHU8xsggnVo+c8s= X-Received: by 2002:a17:90a:bb92:: with SMTP id v18mr17246584pjr.54.1584308480375; Sun, 15 Mar 2020 14:41:20 -0700 (PDT) Received: from google.com ([2620:15c:202:201:476b:691:abc3:38db]) by smtp.gmail.com with ESMTPSA id i13sm13250334pfd.180.2020.03.15.14.41.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Mar 2020 14:41:19 -0700 (PDT) Date: Sun, 15 Mar 2020 14:41:19 -0700 From: Prashant Malani To: Enric Balletbo i Serra Cc: linux-kernel@vger.kernel.org, furquan@chromium.org, Benson Leung Subject: Re: [PATCH 3/3] platform/chrome: notify: Pull PD_HOST_EVENT status Message-ID: <20200315214119.GB185829@google.com> References: <20200312100809.21153-1-pmalani@chromium.org> <20200312100809.21153-4-pmalani@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Enric, Thanks for the review as always. Kindly see inline: On Fri, Mar 13, 2020 at 01:43:24PM +0100, Enric Balletbo i Serra wrote: > Hi Prashant, > > On 12/3/20 11:08, Prashant Malani wrote: > > Read the PD host even status from the EC and send that to the notifier > > listeners, for more fine-grained event information. > > > > Signed-off-by: Prashant Malani > > --- > > drivers/platform/chrome/cros_usbpd_notify.c | 87 ++++++++++++++++++++- > > 1 file changed, 84 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/platform/chrome/cros_usbpd_notify.c b/drivers/platform/chrome/cros_usbpd_notify.c > > index d2dbf7017e29c..3d9db4146217e 100644 > > --- a/drivers/platform/chrome/cros_usbpd_notify.c > > +++ b/drivers/platform/chrome/cros_usbpd_notify.c > > @@ -53,11 +53,91 @@ void cros_usbpd_unregister_notify(struct notifier_block *nb) > > } > > EXPORT_SYMBOL_GPL(cros_usbpd_unregister_notify); > > > > +/** > > + * cros_ec_pd_command - Send a command to the EC. > > + * > > + * @ec_dev: EC device > > + * @command: EC command > > + * @outdata: EC command output data > > + * @outsize: Size of outdata > > + * @indata: EC command input data > > + * @insize: Size of indata > > + * > > + * Return: 0 on success, < 0 on failure. > > + */ > > +static int cros_ec_pd_command(struct cros_ec_device *ec_dev, > > + int command, > > + uint8_t *outdata, > > + int outsize, > > + uint8_t *indata, > > + int insize) > > +{ > > + int ret; > > + struct cros_ec_command *msg; > > Reverse x-mas tree, please. > Done. > struct cros_ec_command *msg; > int ret; > > > + > > + msg = kzalloc(sizeof(*msg) + max(insize, outsize), GFP_KERNEL); > > + if (!msg) > > + return -EC_RES_ERROR; > > Use standard linux error codes please, in that case -ENOMEM. > Done. > > + > > + msg->command = command; > > + msg->outsize = outsize; > > + msg->insize = insize; > > + > > + if (outsize) > > + memcpy(msg->data, outdata, outsize); > > + > > + ret = cros_ec_cmd_xfer_status(ec_dev, msg); > > + if (ret < 0) > > + goto error; > > + > > + if (insize) > > + memcpy(indata, msg->data, insize); > > + ret = EC_RES_SUCCESS; > > Standard linux error codes, just return what cros_ec_cmd_xfer_status returns. Done. > > > +error: > > + kfree(msg); > > + return ret; > > +} > > + > > +static void cros_usbpd_get_event_and_notify(struct device *dev, > > + struct cros_ec_device *ec_dev) > > +{ > > + struct ec_response_host_event_status host_event_status; > > + u32 event = 0; > > + int ret; > > + > > + /* > > + * We still send a 0 event out to older devices which don't > > + * have the updated device heirarchy. > > + */ > > + if (!ec_dev) { > > Ok, remembering my comment in previous patch it makes sense to check for ec_dev, > but see below ... > > > + dev_dbg(dev, > > + "EC device inaccessible; sending 0 event status.\n"); > > + goto send_notify; > > + } > > + > > + /* Check for PD host events on EC. */ > > + ret = cros_ec_pd_command(ec_dev, EC_CMD_PD_HOST_EVENT_STATUS, > > + NULL, 0, > > + (uint8_t *)&host_event_status, > > + sizeof(host_event_status)); > > + if (ret < 0) { > > + dev_warn(dev, "Can't get host event status (err: %d)\n", ret); > > This print is unneeded, a error will be printed already if it fails. Done. > > > + goto send_notify; > > + } > > + > > + event = host_event_status.status; > > + > > +send_notify: > > + blocking_notifier_call_chain(&cros_usbpd_notifier_list, event, NULL); > > +} > > + > > #ifdef CONFIG_ACPI > > > > static void cros_usbpd_notify_acpi(acpi_handle device, u32 event, void *data) > > { > > - blocking_notifier_call_chain(&cros_usbpd_notifier_list, event, NULL); > > + struct cros_usbpd_notify_data *pdnotify = data; > > + > > + cros_usbpd_get_event_and_notify(pdnotify->dev, pdnotify->ec); > > } > > > > static int cros_usbpd_notify_probe_acpi(struct platform_device *pdev) > > @@ -144,6 +224,8 @@ static int cros_usbpd_notify_plat(struct notifier_block *nb, > > unsigned long queued_during_suspend, > > void *data) > > { > > + struct cros_usbpd_notify_data *pdnotify = container_of(nb, > > + struct cros_usbpd_notify_data, nb); > > struct cros_ec_device *ec_dev = (struct cros_ec_device *)data; > > u32 host_event = cros_ec_get_host_event(ec_dev); > > > > Not related to this patch but as you introduced the possibility to have ec_dev > NULL, crash here. notify_plat() would only be called for the cros-MFD initialization (i.e the "platform" case) situation, so ec_dev can be guranteed to be present here. > > > > @@ -151,8 +233,7 @@ static int cros_usbpd_notify_plat(struct notifier_block *nb, > > return NOTIFY_BAD; > > > > if (host_event & EC_HOST_EVENT_MASK(EC_HOST_EVENT_PD_MCU)) { > > - blocking_notifier_call_chain(&cros_usbpd_notifier_list, > > - host_event, NULL); > > + cros_usbpd_get_event_and_notify(pdnotify->dev, ec_dev); > > return NOTIFY_OK; > > } > > return NOTIFY_DONE; > >