[PATCH 1/1] usb: xhci: avoid type conversion of void *

Marek Vasut marex at denx.de
Thu Oct 1 10:31:24 CEST 2020


On 10/1/20 1:43 AM, Heinrich Schuchardt wrote:
> On 9/29/20 10:20 PM, Marek Vasut wrote:
>> On 9/29/20 10:03 PM, Heinrich Schuchardt wrote:
>>> void * can be assigned to any pointer variable. Avoid unnecessary
>>> conversions.
>>>
>>> Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
>>> ---
>>>  drivers/usb/host/xhci-mem.c | 21 +++++++++------------
>>>  1 file changed, 9 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
>>> index 1da0524aa0..4c303ae705 100644
>>> --- a/drivers/usb/host/xhci-mem.c
>>> +++ b/drivers/usb/host/xhci-mem.c
>>> @@ -280,10 +280,10 @@ static struct xhci_segment *xhci_segment_alloc(void)
>>>  {
>>>  	struct xhci_segment *seg;
>>>
>>> -	seg = (struct xhci_segment *)malloc(sizeof(struct xhci_segment));
>>> +	seg = malloc(sizeof(struct xhci_segment));
>>
>> As far as I remember, the compiler used to complain about assignment
>> from a different type without a cast ?
> 
> Under the ANSI C standard, the cast is redundant.

U-Boot isn't compiled with -ansi to my knowledge.

> void * is an incomplete type. You can assign it to any pointer and any
> pointer can be assigned to it, both without casting.
> 
> For other data types you are right. GCC will not accept an assignment
> without conversion.
> 
> In C++ you need to cast to assign void * to other types.
> 
>> btw. you might also do a patch which does malloc(sizeof(*seg)); while at it.
> 
> Sure if you prefer that I will respin the patch.

Separate patch is fine. I'll queue this one into next shortly.


More information about the U-Boot mailing list