Peter Maydell <peter.mayd...@linaro.org> writes:

> On Thu, 7 Mar 2019 at 09:58, Gerd Hoffmann <kra...@redhat.com> wrote:
>>
>> From: Bandan Das <b...@redhat.com>
>>
>> During a write, free up the "path" before getting more data.
>> Also, while we at it, remove the confusing usage of d->fd for
>> storing mkdir status
>>
>> Spotted by Coverity: CID 1398642
>>
>> Signed-off-by: Bandan Das <b...@redhat.com>
>> Message-id: 20190306210409.14842-3-...@redhat.com
>> Signed-off-by: Gerd Hoffmann <kra...@redhat.com>
>
> Hi; Coverity found an issue with the code change here
> (CID 1399415):
>
>> index 4dde14fc7887..1f22284949df 100644
>> --- a/hw/usb/dev-mtp.c
>> +++ b/hw/usb/dev-mtp.c
>> @@ -1605,7 +1605,7 @@ static int usb_mtp_update_object(MTPObject *parent, 
>> char *name)
>>      return ret;
>>  }
>>
>> -static void usb_mtp_write_data(MTPState *s)
>> +static int usb_mtp_write_data(MTPState *s)
>
> Here we change usb_mtp_write_data() to return an error code...
>
>>  {
>>      MTPData *d = s->data_out;
>>      MTPObject *parent =
>
>> @@ -1727,14 +1731,12 @@ static void usb_mtp_write_metadata(MTPState *s, 
>> uint64_t dlen)
>>      s->write_pending = true;
>>
>>      if (s->dataset.format == FMT_ASSOCIATION) {
>> -        usb_mtp_write_data(s);
>> -        /* next_handle will be allocated to the newly created dir */
>> -        if (d->fd == -1) {
>> +        if (usb_mtp_write_data(s)) {
>> +            /* next_handle will be allocated to the newly created dir */
>>              usb_mtp_queue_result(s, RES_STORE_FULL, d->trans,
>>                                   0, 0, 0, 0);
>>              return;
>
> ...and we updated this callsite to check the error return value.
>
> But the two places in usb_mtp_get_data() that call
> usb_mtp_write_metadata() still don't check its return
> value: don't they need to handle failure too?
>
I believe this is ok because:
The return value of usb_mtp_write_data is only used to check if mkdir
failed and update s->result in usb_mtp_write_metadata().
The next time usb_mtp_handle_data is called, it will process s->result. 

Bandan

> thanks
> -- PMM

Reply via email to