NetBSD Problem Report #52580

From www@NetBSD.org  Sat Sep 30 06:28:47 2017
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 51A9E7A180
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 30 Sep 2017 06:28:47 +0000 (UTC)
Message-Id: <20170930062846.6BD707A287@mollari.NetBSD.org>
Date: Sat, 30 Sep 2017 06:28:46 +0000 (UTC)
From: isaki@pastel-flower.jp
Reply-To: isaki@pastel-flower.jp
To: gnats-bugs@NetBSD.org
Subject: audio: init_output/input called multiple times per open
X-Send-Pr-Version: www-1.0

>Number:         52580
>Category:       kern
>Synopsis:       audio: init_output/input called multiple times per open
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    nat
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Sep 30 06:30:00 +0000 2017
>Closed-Date:    Fri Oct 27 20:54:26 +0000 2017
>Last-Modified:  Fri Oct 27 20:54:26 +0000 2017
>Originator:     Tetsuya Isaki
>Release:        NetBSD 8.99.3
>Organization:
>Environment:
NetBSD 8.99.3 i386
>Description:
When open an audio device for writing, hw->init_output() is called
multiple times.  This call should only be one at a time.

Similarly, when open an audio device for reading, hw->init_input()
is called multiple times.  This call should also only be one at a time.
>How-To-Repeat:
Run audioplay(1)/audiorecord(1).
Even if your device does not use init_input/output method,
the problem can be easily seen with this patch.

--- sys/dev/audio.c
+++ sys/dev/audio.c
@@ -2028,6 +2028,7 @@ audio_initbufs(struct audio_softc *sc, struct virtual_channel *vc)
 		audio_init_ringbuffer(sc, &vc->sc_mrr,
 		    AUMODE_RECORD);
 		if (sc->sc_opens == 0 && (vc->sc_mode & AUMODE_RECORD)) {
+printf("hw->init_input\n");
 			if (hw->init_input) {
 				error = hw->init_input(sc->hw_hdl,
 				    vc->sc_mrr.s.start,
@@ -2044,6 +2045,7 @@ audio_initbufs(struct audio_softc *sc, struct virtual_channel *vc)
 		    AUMODE_PLAY);
 		vc->sc_sil_count = 0;
 		if (sc->sc_opens == 0 && (vc->sc_mode & AUMODE_PLAY)) {
+printf("hw->init_output\n");
 			if (hw->init_output) {
 				error = hw->init_output(sc->hw_hdl,
 				    vc->sc_mpr.s.start,


% audioplay music.au
hw->init_output
hw->init_output
% audioplay music.au
hw->init_output
hw->init_output
hw->init_output

>Fix:
N/A

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: kern-bug-people->nat
Responsible-Changed-By: nat@NetBSD.org
Responsible-Changed-When: Sun, 01 Oct 2017 21:41:41 +0000
Responsible-Changed-Why:
Take.


From: "Nathanial Sloss" <nat@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52580 CVS commit: src/sys/dev
Date: Sun, 1 Oct 2017 21:49:20 +0000

 Module Name:	src
 Committed By:	nat
 Date:		Sun Oct  1 21:49:20 UTC 2017

 Modified Files:
 	src/sys/dev: audio.c

 Log Message:
 Ensure proper use of sc_opens (play back) and sc_recopens (recording).
 Fix logic for /dev/sound so audiosetinfo is only called once.

 These changes are to ensure that init_output/input is only called once for
 the respective function play back or recording.  For multiple recording or
 plack back streams init_input/output is only called once fot the first
 play/rec stream.

 This addresses PR kern/52580, PR kern/52581 and PR kern/52582 analyzed and
 reported by isaki@.


 To generate a diff of this commit:
 cvs rdiff -u -r1.409 -r1.410 src/sys/dev/audio.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: nat@NetBSD.org
State-Changed-When: Fri, 27 Oct 2017 20:54:26 +0000
State-Changed-Why:
This has been fixed.  Thanks for the analysis and PR!


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.