Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1634617 > unrolled thread

[usb-gadget-udc] question about null check after calling phys_to_virt() function

Started by"Gustavo A. R. Silva" <garsilva@embeddedor.com>
First post2017-05-02 22:50 +0200
Last post2017-05-02 22:50 +0200
Articles 1 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [usb-gadget-udc] question about null check after calling  phys_to_virt() function "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-05-02 22:50 +0200

#1634617 — [usb-gadget-udc] question about null check after calling phys_to_virt() function

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-05-02 22:50 +0200
Subject[usb-gadget-udc] question about null check after calling phys_to_virt() function
Message-ID<tCMUa-3a8-9@gated-at.bofh.it>
Hello everybody,

While looking into Coverity ID 145958 I ran into the following piece  
of code at drivers/usb/gadget/udc/amd5536udc.c:852:

} else if (i == buf_len) {
         /* first td */
         td = (struct udc_data_dma *)phys_to_virt(
                                 req->td_data->next);
         td->status = 0;
} else {
         td = (struct udc_data_dma *)phys_to_virt(last->next);
         td->status = 0;
}

if (td)
         td->bufptr = req->req.dma + i; /* assign buffer */
else
         break;

The issue here is that _td_ pointer is being dereferenced before null check.

After searching for calls to phys_to_virt() function, I've noticed  
that is not common at all to test the returned address value.

So either the null check at line 862 is not needed or a null check  
before each td->status = 0; needs to be added.

I think it would be good to apply a patch like the following one:

-                       td->status = 0;
+
+                       if (td)
+                               td->status = 0;
+                       else
+                               break;
                 } else {
                         td = (struct udc_data_dma *)phys_to_virt(last->next);
-                       td->status = 0;
+
+                       if (td)
+                               td->status = 0;
+                       else
+                               break;
                 }

-               if (td)
-                       td->bufptr = req->req.dma + i; /* assign buffer */
-               else
-                       break;
+               td->bufptr = req->req.dma + i; /* assign buffer */


What do you think?

Thanks in advance for your comments
--
Gustavo A. R. Silva

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web