Re: [PATCH v5 3/8] usb: typec: ucsi: Implement ChromeOS UCSI driver

Łukasz Bartosik
2024-09-06T15:19:26Z

On Fri, Sep 6, 2024 at 4:20 PM Heikki Krogerus
<heikki.krogerus@linux.intel.com> wrote:
>
> Hi,
>
> Sorry to go back on this, but I noticed something..
>
> On Tue, Sep 03, 2024 at 04:30:28PM +0000, Łukasz Bartosik wrote:
> > +static int cros_ucsi_async_control(struct ucsi *ucsi, u64 cmd)
> > +{
> > + struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi);
> > + struct ec_params_ucsi_ppm_set *req;
> > + size_t req_len;
> > + int ret;
> > +
> > + req_len = sizeof(struct ec_params_ucsi_ppm_set) + sizeof(cmd);
> > + req = kzalloc(req_len, GFP_KERNEL);
> > + if (!req)
> > + return -ENOMEM;
>
> Where is the memory for req released?
>
> First I though that cros_ec_cmd() does it, but it's actually
> allocating it's own cros_ec_command, and then releasing that in the
> end, so I just got confused about it.
>
> Is this a memory leak, or am I missing something?
>

Yes, you are right this is a memory leak.
Thanks for catching this. I will fix it in the next version.

Regards,
Lukasz

> > +
> > + req->offset = UCSI_CONTROL;
> > + memcpy(req->data, &cmd, sizeof(cmd));
> > + ret = cros_ec_cmd(udata->ec, 0, EC_CMD_UCSI_PPM_SET,
> > + req, req_len, NULL, 0);
> > + if (ret < 0) {
> > + dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_SET: error=%d", ret);
> > + return ret;
> > + }
> > + return 0;
> > +}
>
> thanks,
>
> --
> heikki