Opened 12 years ago

Closed 5 years ago

Last modified 4 years ago

#8530 closed bug (fixed)

USB bus manager does not support unaligned read/writes

Reported by: pulkomandy Owned by: mmlr
Priority: normal Milestone: R1/beta2
Component: Drivers/USB Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

I'm trying to perform some simple sector read/write operations on an usb mass storage device (SD card reader).

The following code works fine :

#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(void)
{
	char* buffer = malloc(512);
	int fd = open("/dev/disk/usb/0/3/raw", O_RDONLY);
	
	lseek(fd, 8192, SEEK_SET);
	
	if (fd < 0)
		perror("open error");
	if (read(fd, buffer, 1) == -1)
		perror("read error");

	close(fd);
	free(buffer);
}

But this one doesn't :

#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(void)
{
	char buffer[512];
	int fd = open("/dev/disk/usb/0/3/raw", O_RDONLY);
	
	lseek(fd, 8192, SEEK_SET);
	
	if (fd < 0)
		perror("open error");
	if (read(fd, buffer, 1) == -1)
		perror("read error");

	close(fd);
}

The only difference is the way buffer is allocated. Our malloc happens to align memory to pages, while allocating on the stack obviously doesn't.

Following message is seen in error log :

KERN: usb error transfer 0: data buffer spans across multiple areas!
KERN: usb error ehci -1: failed to add pending transfer

From then on, the device is not accessible anymore by any means and needs to be unplugged/replugged.

Change History (4)

comment:1 by phoudoin, 12 years ago

Well, three remarks:

  1. it's not limited to EHCI, as it's an USB bus manager issue, not a controler one.
  2. it's not a page alignment issue, but lack of multiple pages support
  3. the fact that it makes the device not accessible anymore is a definitive extra bug, that should be tracking down: an explicitly handled error in the stack should not let the device access in a broken state

comment:2 by waddlesplash, 9 years ago

Summary: EHCI usb driver does not support unaligned read/writesUSB bus manager does not support unaligned read/writes

Changing summary as per comment.

comment:3 by pulkomandy, 5 years ago

Resolution: fixed
Status: newclosed

Not reproductible anymore.

comment:4 by nielx, 4 years ago

Milestone: R1R1/beta2

Assign tickets with status=closed and resolution=fixed within the R1/beta2 development window to the R1/beta2 Milestone

Note: See TracTickets for help on using tickets.