public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/2] usb: gadget: sdp: fix pointer casts for 64bit archs
Date: Thu, 15 Feb 2018 09:49:26 +0100	[thread overview]
Message-ID: <20180215094926.6887ccf8@jawa> (raw)
In-Reply-To: <20180215060856.6740-2-a.heider@gmail.com>

Hi Andre,

> The SDP protocol contains multiple 32bit pointers. Add a helper
> function to get a valid pointer from these values and use it.

Is there any special rationale behind this?

> 
> Signed-off-by: Andre Heider <a.heider@gmail.com>
> ---
>  drivers/usb/gadget/f_sdp.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
> index 6da0530095..43c5cfbb77 100644
> --- a/drivers/usb/gadget/f_sdp.c
> +++ b/drivers/usb/gadget/f_sdp.c
> @@ -230,6 +230,11 @@ static struct usb_gadget_strings
> *sdp_generic_strings[] = { NULL,
>  };
>  
> +static inline void *sdp_ptr(u32 val)
> +{
> +	return (void *)(uintptr_t)val;
> +}

From what I see from the code the (void *) cast shall be enough.

> +
>  static void sdp_rx_command_complete(struct usb_ep *ep, struct
> usb_request *req) {
>  	struct f_sdp *sdp = req->context;
> @@ -344,7 +349,7 @@ static void sdp_rx_data_complete(struct usb_ep
> *ep, struct usb_request *req) }
>  
>  	if (sdp->state == SDP_STATE_RX_FILE_DATA) {
> -		memcpy((void *)sdp->dnl_address, req->buf + 1,
> datalen);
> +		memcpy(sdp_ptr(sdp->dnl_address), req->buf + 1,
> datalen); sdp->dnl_address += datalen;
>  	}
>  
> @@ -622,7 +627,7 @@ static u32 sdp_jump_imxheader(void *address)
>  	}
>  
>  	printf("Jumping to 0x%08x\n", headerv2->entry);
> -	entry = (void *)headerv2->entry;
> +	entry = sdp_ptr(headerv2->entry);
>  	entry();
>  
>  	/* The image probably never returns hence we won't reach
> that point */ @@ -665,7 +670,7 @@ static void sdp_handle_in_ep(void)
>  		if (datalen > 64)
>  			datalen = 64;
>  
> -		memcpy(&data[1], (void *)sdp_func->dnl_address,
> datalen);
> +		memcpy(&data[1], sdp_ptr(sdp_func->dnl_address),
> datalen); sdp_func->in_req->length = 65;
>  
>  		sdp_func->dnl_bytes_remaining -= datalen;
> @@ -676,7 +681,7 @@ static void sdp_handle_in_ep(void)
>  		break;
>  	case SDP_STATE_JUMP:
>  		printf("Jumping to header at 0x%08x\n",
> sdp_func->jmp_address);
> -		status = sdp_jump_imxheader((void
> *)sdp_func->jmp_address);
> +		status =
> sdp_jump_imxheader(sdp_ptr(sdp_func->jmp_address)); 
>  		/* If imx header fails, try some U-Boot specific
> headers */ if (status) {




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180215/e1fa5bc7/attachment.sig>

  reply	other threads:[~2018-02-15  8:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-15  6:08 [U-Boot] [PATCH 1/2] usb: gadget: sdp: add missing line breaks Andre Heider
2018-02-15  6:08 ` [U-Boot] [PATCH 2/2] usb: gadget: sdp: fix pointer casts for 64bit archs Andre Heider
2018-02-15  8:49   ` Lukasz Majewski [this message]
2018-02-15  8:58     ` Andre Heider
2018-02-15  9:06       ` Lukasz Majewski
2018-02-15  9:17   ` [U-Boot] [PATCH v2 2/2] usb: gadget: sdp: fix pointer cast warnings " Andre Heider
2018-02-15  8:59 ` [U-Boot] [PATCH 1/2] usb: gadget: sdp: add missing line breaks Lukasz Majewski
2018-02-15  9:15   ` Stefan Agner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180215094926.6887ccf8@jawa \
    --to=lukma@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox