From nobody@FreeBSD.org  Fri Apr 15 21:34:12 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id DAD971065670
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 15 Apr 2011 21:34:12 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id C85E08FC0A
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 15 Apr 2011 21:34:12 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p3FLYCGK027613
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 15 Apr 2011 21:34:12 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p3FLYCCd027612;
	Fri, 15 Apr 2011 21:34:12 GMT
	(envelope-from nobody)
Message-Id: <201104152134.p3FLYCCd027612@red.freebsd.org>
Date: Fri, 15 Apr 2011 21:34:12 GMT
From: Grigori Goronzy <greg@chown.ath.cx>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [sound] [patch] OSS4/VPC is broken on 64-bit platforms
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         156433
>Category:       kern
>Synopsis:       [sound] [patch] OSS4/VPC is broken on 64-bit platforms
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    avg
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 15 21:40:07 UTC 2011
>Closed-Date:    Sat Nov 05 11:20:51 UTC 2011
>Last-Modified:  Sat Nov 05 11:20:51 UTC 2011
>Originator:     Grigori Goronzy
>Release:        RELENG_8
>Organization:
>Environment:
FreeBSD fbsd.chown.ath.cx 8.2-RELEASE FreeBSD 8.2-RELEASE #1: Fri Apr 15 19:04:14 UTC 2011     root@fbsd.chown.ath.cx:/usr/obj/usr/src/sys/MINE  amd64

>Description:
The OSS4 API for volume control is broken on 64-bit platforms. I tracked it down and noticed that the ioctl passthrough/wrapper uses "int" where it should use an "u_long" for passing ioctl parameters. On most 32-bit platforms this is not an issue, as sizeof(int)==sizeof(u_long). Not so on 64-bit platforms, though.

This boils down to a signed vs unsigned issue when the parameter is converted from int to u_long. This affects the SNDCTL_DSP_SETPLAYVOL ioctl and possibly others.
>How-To-Repeat:
1. Install mplayer2
2. Play an audio file through mplayer2's OSS output (which uses the aforementioned API call)
3. Try to change volume with "9" and "0" keys
4. Nothing happens
>Fix:
The attached patch.

Patch attached with submission follows:

--- sys/dev/sound/pcm/dsp.c.orig	2011-04-15 20:24:23.000000000 +0000
+++ sys/dev/sound/pcm/dsp.c	2011-04-15 20:38:30.000000000 +0000
@@ -1055,7 +1055,8 @@
 {
     	struct pcm_channel *chn, *rdch, *wrch;
 	struct snddev_info *d;
-	int *arg_i, ret, tmp, xcmd;
+	int *arg_i, ret, tmp;
+	u_long xcmd;
 
 	d = dsp_get_info(i_dev);
 	if (!DSP_REGISTERED(d, i_dev))


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-multimedia 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sun Apr 17 01:12:11 UTC 2011 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=156433 

From: Test Rat <ttsestt@gmail.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/156433: [sound] [patch] OSS4/VPC is broken on 64-bit platforms
Date: Fri, 29 Jul 2011 04:25:37 +0400

 --=-=-=
 Content-Type: text/plain
 
 Any chance the fix will be committed before 9.0-RELEASE? The ioctl is
 used by more apps than just mplayer2, see
 
   http://google.com/codesearch?q=SNDCTL_DSP_SETPLAYVOL
   (gst-plugins-good, wine, xmms2, moc, qmmp, etc)
 
 I've tried to change volume with attached test program but it stays the same.
 This is also reflected in /dev/sndstat, try
 
   http://people.freebsd.org/~ariff/utils/appsmixer
 
 
 --=-=-=
 Content-Type: text/plain
 Content-Disposition: attachment; filename=test_vol.c
 
 #include <sys/ioctl.h>
 #include <sys/soundcard.h>
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <termios.h>
 #include <unistd.h>
 
 int audio_fd;
 int lvol, rvol;
 
 void
 setplayvol(void)
 {
 	int mask = lvol | rvol << 8;
 	if(ioctl(audio_fd, SNDCTL_DSP_SETPLAYVOL, &mask) < 0)
 		err(errno, "SNDCTL_DSP_SETPLAYVOL failed");
 }
 
 void
 getplayvol(void)
 {
 	int mask;
 	if(ioctl(audio_fd, SNDCTL_DSP_GETPLAYVOL, &mask) < 0)
 		err(errno, "SNDCTL_DSP_GETPLAYVOL failed");
 	lvol = mask & 0x00ff;
 	rvol = (mask & 0xff00) >> 8;
 	printf("\rvol is %d:%d  ", lvol, rvol);
 }
 
 int
 main(void)
 {
 	char ch, buf[] = "noise";
 	struct termios t;
 
 	if((audio_fd = open("/dev/dsp", O_WRONLY, 0)) < 0)
 		err(errno, "open failed");
 
 	printf("hit ^C to abort\n");
 	getplayvol();
 
 	tcgetattr(0, &t);
 	t.c_lflag &= ~(ECHO|ICANON);
 	tcsetattr(0, TCSANOW, &t);
 
 	while ((ch = getchar()) != EOF) {
 		switch(ch) {
 		case '+':
 			if(lvol < 100 && rvol < 100) {
 				lvol++;
 				rvol++;
 			}
 			break;
 		case '-':
 			if(lvol > 0 && rvol > 0) {
 				lvol--;
 				rvol--;
 			}
 			break;
 		case 'L':
 		case 'l':
 			if(lvol < 100)
 				lvol++;
 			break;
 		case 'R':
 		case 'r':
 			if(rvol < 100)
 				rvol++;
 			break;
 		case '\014': /* ^L */
 			if(lvol > 0)
 				lvol--;
 			break;
 		case '\022': /* ^R */
 			if(rvol > 0)
 				rvol--;
 			break;
 		case '\007': /* ^G */
 			close(audio_fd);
 			if((audio_fd = open("/dev/dsp", O_WRONLY, 0)) < 0)
 				err(errno, "open failed");
 			getplayvol();
 			continue;
 		default: /* any other key produces noise */
 			write(audio_fd, buf, sizeof(buf));
 			continue;
 		}
 		setplayvol();
 		getplayvol();
 	}
 
 	close(audio_fd);
 	return 0;
 }
 
 --=-=-=--

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/156433: commit references a PR
Date: Mon, 12 Sep 2011 08:38:35 +0000 (UTC)

 Author: avg
 Date: Mon Sep 12 08:38:21 2011
 New Revision: 225505
 URL: http://svn.freebsd.org/changeset/base/225505
 
 Log:
   dsp_ioctl: fix type of variable used to store ioctl request
   
   PR:		kern/156433
   Submitted by:	Grigori Goronzy <greg@chown.ath.cx>
   Reviewed by:	hselasky
   Approved by:	re (kib)
   MFC after:	1 week
 
 Modified:
   head/sys/dev/sound/pcm/dsp.c
 
 Modified: head/sys/dev/sound/pcm/dsp.c
 ==============================================================================
 --- head/sys/dev/sound/pcm/dsp.c	Mon Sep 12 06:41:13 2011	(r225504)
 +++ head/sys/dev/sound/pcm/dsp.c	Mon Sep 12 08:38:21 2011	(r225505)
 @@ -1062,7 +1062,8 @@ dsp_ioctl(struct cdev *i_dev, u_long cmd
  {
      	struct pcm_channel *chn, *rdch, *wrch;
  	struct snddev_info *d;
 -	int *arg_i, ret, tmp, xcmd;
 +	u_long xcmd;
 +	int *arg_i, ret, tmp;
  
  	d = dsp_get_info(i_dev);
  	if (!DSP_REGISTERED(d, i_dev))
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: avg 
State-Changed-When: Mon Sep 12 08:42:41 UTC 2011 
State-Changed-Why:  
A variant of the patch is committed to head. 


Responsible-Changed-From-To: freebsd-multimedia->avg 
Responsible-Changed-By: avg 
Responsible-Changed-When: Mon Sep 12 08:42:41 UTC 2011 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=156433 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/156433: commit references a PR
Date: Sat,  5 Nov 2011 11:04:45 +0000 (UTC)

 Author: avg
 Date: Sat Nov  5 11:04:25 2011
 New Revision: 227106
 URL: http://svn.freebsd.org/changeset/base/227106
 
 Log:
   MFC r225505: dsp_ioctl: fix type of variable used to store ioctl request
   
   PR:		kern/156433
 
 Modified:
   stable/8/sys/dev/sound/pcm/dsp.c
 Directory Properties:
   stable/8/sys/   (props changed)
   stable/8/sys/amd64/include/xen/   (props changed)
   stable/8/sys/cddl/contrib/opensolaris/   (props changed)
   stable/8/sys/contrib/dev/acpica/   (props changed)
   stable/8/sys/contrib/pf/   (props changed)
 
 Modified: stable/8/sys/dev/sound/pcm/dsp.c
 ==============================================================================
 --- stable/8/sys/dev/sound/pcm/dsp.c	Sat Nov  5 10:00:29 2011	(r227105)
 +++ stable/8/sys/dev/sound/pcm/dsp.c	Sat Nov  5 11:04:25 2011	(r227106)
 @@ -1062,7 +1062,8 @@ dsp_ioctl(struct cdev *i_dev, u_long cmd
  {
      	struct pcm_channel *chn, *rdch, *wrch;
  	struct snddev_info *d;
 -	int *arg_i, ret, tmp, xcmd;
 +	u_long xcmd;
 +	int *arg_i, ret, tmp;
  
  	d = dsp_get_info(i_dev);
  	if (!DSP_REGISTERED(d, i_dev))
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/156433: commit references a PR
Date: Sat,  5 Nov 2011 11:18:59 +0000 (UTC)

 Author: avg
 Date: Sat Nov  5 11:18:46 2011
 New Revision: 227107
 URL: http://svn.freebsd.org/changeset/base/227107
 
 Log:
   MFC r225505: dsp_ioctl: fix type of variable used to store ioctl request
   
   PR:		kern/156433
 
 Modified:
   stable/7/sys/dev/sound/pcm/dsp.c
 Directory Properties:
   stable/7/sys/   (props changed)
   stable/7/sys/cddl/contrib/opensolaris/   (props changed)
   stable/7/sys/contrib/dev/acpica/   (props changed)
   stable/7/sys/contrib/pf/   (props changed)
 
 Modified: stable/7/sys/dev/sound/pcm/dsp.c
 ==============================================================================
 --- stable/7/sys/dev/sound/pcm/dsp.c	Sat Nov  5 11:04:25 2011	(r227106)
 +++ stable/7/sys/dev/sound/pcm/dsp.c	Sat Nov  5 11:18:46 2011	(r227107)
 @@ -778,7 +778,8 @@ dsp_ioctl(struct cdev *i_dev, u_long cmd
  {
      	struct pcm_channel *chn, *rdch, *wrch;
  	struct snddev_info *d;
 -	int *arg_i, ret, kill, tmp, xcmd;
 +	u_long xcmd;
 +	int *arg_i, ret, kill, tmp;
  
  	d = dsp_get_info(i_dev);
  	if (!DSP_REGISTERED(d, i_dev))
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: avg 
State-Changed-When: Sat Nov 5 11:20:21 UTC 2011 
State-Changed-Why:  
The fix is MFCed. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=156433 
>Unformatted:
