[U-Boot] [PATCH] USB: Use (get|put)_unaligned_le16 for accessing wMaxPacketSize

Stefan Kristiansson stefan.kristiansson at saunalahti.fi
Thu Dec 15 07:05:46 CET 2011


Hi Tom,

after taking a second look at this a couple of things came to mind

On Wed, Dec 14, 2011 at 03:20:03PM -0700, Tom Rini wrote:
> In 9792987721c7980453fe6447c3fa6593b44f8458 Stefan describes a usecase
> where the previous behavior of leaving wMaxPacketSize be unaligned
> caused fatal problems.  The initial fix for this problem was incomplete
> however as it showed another cases of non-aligned access that previously
> worked implicitly.  This switches to making sure that all access of
> wMaxPacketSize are done via (get|put)_unaligned_le16.
> 

Why the _le16? Shouldn't it just be (get|put)_unaligned?

> -			le16_to_cpus(&(dev->config.if_desc[ifno].ep_desc[epno].\
> -							       wMaxPacketSize));
> +			ep_wMaxPacketSize = get_unaligned_le16(&dev->config.\
> +							if_desc[ifno].\
> +							ep_desc[epno].\
> +							wMaxPacketSize);
> +			le16_to_cpus(&ep_wMaxPacketSize);
>  			USB_PRINTF("if %d, ep %d\n", ifno, epno);
>  			break;
>  		default:

Since this code is changing the wMaxPacketSize, it should probably be:

			ep_wMaxPacketSize = get_unaligned(&dev->config.\
							if_desc[ifno].\
							ep_desc[epno].\
							wMaxPacketSize);
			put_unaligned(le16_to_cpu(ep_wMaxPacketSize),
					&dev->config.\
					if_desc[ifno].\
					ep_desc[epno].\
					wMaxPacketSize);

Stefan


More information about the U-Boot mailing list