Bug 14237

Summary: dvision of signed and unsigned operators usb_stream.c
Product: Drivers Reporter: Martin Ettl (ettl.martin)
Component: Sound(OSS)Assignee: drivers_sound
Status: CLOSED WILL_NOT_FIX    
Severity: normal CC: alan
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 2.6.31 Subsystem:
Regression: No Bisected commit-id:

Description Martin Ettl 2009-09-26 17:04:04 UTC
Hello,

i have checked the linux kernel with the static code analysis tool cppcheck. It brought up an issue in file linux-2.6.31/sound/usb/usx2y/usb_stream.c at line 177. Cppcheck printed the following warning:

- dvision of signed and unsigned operators at line 177

Take a look at the code:

struct usb_stream *usb_stream_new(struct usb_stream_kernel *sk,
				  struct usb_device *dev,
				  unsigned in_endpoint, unsigned out_endpoint,
				  unsigned sample_rate, unsigned use_packsize,
				  unsigned period_frames, unsigned frame_size)
{
	int packets, max_packsize;
	int in_pipe, out_pipe;
	int read_size = sizeof(struct usb_stream);
	int write_size;
	int usb_frames = dev->speed == USB_SPEED_HIGH ? 8000 : 1000;
	int pg;

	in_pipe = usb_rcvisocpipe(dev, in_endpoint);
	out_pipe = usb_sndisocpipe(dev, out_endpoint);

	max_packsize = use_packsize ?
		use_packsize : usb_maxpacket(dev, in_pipe, 0);

	/*
		t_period = period_frames / sample_rate
		iso_packs = t_period / t_iso_frame
			= (period_frames / sample_rate) * (1 / t_iso_frame)
	*/

177	packets = period_frames * usb_frames / sample_rate + 1;
....

Indeed, the tool is right, at line 177 there is a division of signed and unsigned operator. This can lead to undifined behaviour!

Best regards

Martin