Messages in this thread |  | | Date | Thu, 14 Jul 2022 03:33:42 +0000 | From | Tzung-Bi Shih <> | Subject | Re: [RESEND PATCH 05/11] platform/chrome: cros_ec_proto: separate cros_ec_wait_until_complete() |
| |
On Wed, Jul 13, 2022 at 11:15:47AM -0700, Guenter Roeck wrote: > On Mon, Jun 27, 2022 at 7:49 PM Tzung-Bi Shih <tzungbi@kernel.org> wrote: > > -static int cros_ec_send_command(struct cros_ec_device *ec_dev, struct cros_ec_command *msg) > > +static int cros_ec_wait_until_complete(struct cros_ec_device *ec_dev, uint32_t *result) > > { > > - int ret = cros_ec_xfer_command(ec_dev, msg); > > + struct cros_ec_command *msg; > > + struct ec_response_get_comms_status *status; > > + int ret = 0, i; > > + > > + msg = kzalloc(sizeof(*msg) + sizeof(*status), GFP_KERNEL); > > + if (!msg) > > + return -ENOMEM; > > AFAICS this is always 24 bytes. I would suggest to allocate it on the > stack to reduce overhead.
Ack.
> > + ret = cros_ec_xfer_command(ec_dev, msg); > > + if (ret == -EAGAIN) > > + continue; > > + if (ret < 0) > > + break; > > With the command allocated on the stack, this can return immediately.
Nack, the function has no goto labels. `return ret` follows the loop immediately. The `break` here doesn't make it to become too complicated. I would prefer to keep it.
> > + > > + *result = msg->result; > > + if (msg->result != EC_RES_SUCCESS) > > + break; > > Again, this can return immediately if the command buffer is on the stack.
Nack. See above.
> > - kfree(status_msg); > > + if (!(status->flags & EC_COMMS_STATUS_PROCESSING)) > > + break; > > Can return immediately.
Nack. See above.
> > + kfree(msg); > > + return ret; > > What should this return on timeout ?
It returns either: * -EAGAIN, if cros_ec_xfer_command() returned -EAGAIN * 0, if EC_COMMS_STATUS_PROCESSING flag was on for EC_COMMAND_RETRIES times so far.
This is a "move" refactor. I would prefer to keep it as is and change the behavior in later patch.
|  |