LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Prashant Malani <pmalani@chromium.org>
To: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Cc: linux-kernel@vger.kernel.org, furquan@chromium.org,
	Benson Leung <bleung@chromium.org>
Subject: Re: [PATCH 3/3] platform/chrome: notify: Pull PD_HOST_EVENT status
Date: Sun, 15 Mar 2020 14:41:19 -0700	[thread overview]
Message-ID: <20200315214119.GB185829@google.com> (raw)
In-Reply-To: <d03c96c0-ea23-5b4e-0be0-0a1a296eeaeb@collabora.com>

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 <pmalani@chromium.org>
> > ---
> >  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;
> > 

      reply	other threads:[~2020-03-15 21:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-12 10:08 [PATCH 0/3] platform/chrome: notify: Use PD_HOST_EVENT_STATUS Prashant Malani
2020-03-12 10:08 ` [PATCH 1/3] platform/chrome: notify: Add driver data struct Prashant Malani
2020-03-13 12:41   ` Enric Balletbo i Serra
2020-03-12 10:08 ` [PATCH 2/3] platform/chrome: notify: Amend ACPI driver to plat Prashant Malani
2020-03-13 12:42   ` Enric Balletbo i Serra
2020-03-15 21:38     ` Prashant Malani
2020-03-16  7:34       ` Prashant Malani
2020-03-12 10:08 ` [PATCH 3/3] platform/chrome: notify: Pull PD_HOST_EVENT status Prashant Malani
2020-03-13 12:43   ` Enric Balletbo i Serra
2020-03-15 21:41     ` Prashant Malani [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200315214119.GB185829@google.com \
    --to=pmalani@chromium.org \
    --cc=bleung@chromium.org \
    --cc=enric.balletbo@collabora.com \
    --cc=furquan@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [PATCH 3/3] platform/chrome: notify: Pull PD_HOST_EVENT status' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).