From nobody Mon Jan 16 13:05:08 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NwXLX6MX6z2sLYT; Mon, 16 Jan 2023 13:05:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NwXLX5stYz4CVB; Mon, 16 Jan 2023 13:05:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673874308; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=llF364LaIMdpOyl5I1nEpDmsDbzzA1foApCUxWfbEiw=; b=GLLwq0PdCFIkIDKdywt3coZzkiDVrz8QJ4AA0q3qC3PfaaosZzfl0WyhBR2g/mbbIJ6aGL hqIVz2LQk2Q3dPZ6ZtRPbbXUUxqyUsOHRlMmQ7aEdoGlg5gSKPPB4bF1xXr/0YpBdFry9D t5oQl7ZXqQNWFSXoSJerL/r2qxLG3cGOGA0LNz9JLNBJbGNhvV4OCSiQT/uMNwZq00HG5v krW0uCoebILyxLVb9mOyiF/NqyRmu9ePDKXQCJMH+K9L7oeKQgksjwGrqzuiYhi34SQLwp 97GyMFLVkYdWqNhir8CP595CnYMK8PmH9OS8vmxAViGLQNfW+asPSFNl/aExeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673874308; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=llF364LaIMdpOyl5I1nEpDmsDbzzA1foApCUxWfbEiw=; b=nyVGdINVzLkGpREW+a2csP2i5KVngwrQ1US8FHB2bgcaEYf9rrGAw4EuonvcnLiqzhL6wy QsynDFGeTZcJI97ghl2L2B+qCaHgEKD7ECBkwidHiv4b/sF0wqVHu/s4xtahTOdPOMeU+P Fakzy+epEiT8GTGYF+shjXRvrPGVEoPjmjO6aonqyn/8bpm7VykrJ4o/l3FunTKar5jSuJ sTPaQ+y/KH41uSsD1YxKhg+wqcAJ8Vl3CBHkwz2ewvCM27wLN6xYxyvcUoMQjPKynsW2KY N6zXWT4GwV0VuPqkNUdqm/DBbENlNZy2dUaB6sJvW4Z/Gld5fgmEzaPY510xaQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1673874308; a=rsa-sha256; cv=none; b=uIEkZsL5t8+gL7dDomGo65oNfqOPQM+FYdbAlw01GIPLcjCw0XmfbghUN4vUCxilJxsOIi 39fxvYv3evDgI6WYqG08Rau2FC/witq4CmISLYUUffj63967uHoAQBw0A3umi8mMuTva8q MZq9WjunI9sJRxJh4LQvzCqg05WTGby9b+cKOGNp4NG7eNPhFfPubBh8x3KsqvB90xx82W ZesD+Glq/Ln7Fclu8lIA+4W8DjeRsLPTF2zS4yvH5Z3MzIUrg0aRmDYtUduycNTixAg6qS t0LrKp1N1tK3GRYI+kGvAGbQpqfv2X4VDQHrYMwab/KYijpm6XwizA7IMKg6eA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NwXLX4wS2z17T1; Mon, 16 Jan 2023 13:05:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30GD58gc021172; Mon, 16 Jan 2023 13:05:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30GD58iV021171; Mon, 16 Jan 2023 13:05:08 GMT (envelope-from git) Date: Mon, 16 Jan 2023 13:05:08 GMT Message-Id: <202301161305.30GD58iV021171@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 5c2b216a1cd8 - main - mixer: Fix default_unit switching with mixers that have no devices List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5c2b216a1cd8de3aabfa9e76ca8f38774acd591e Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=5c2b216a1cd8de3aabfa9e76ca8f38774acd591e commit 5c2b216a1cd8de3aabfa9e76ca8f38774acd591e Author: Mark Johnston AuthorDate: 2023-01-16 13:02:54 +0000 Commit: Mark Johnston CommitDate: 2023-01-16 13:02:54 +0000 mixer: Fix default_unit switching with mixers that have no devices Apparently it's possible for a mixer to have no devices: $ mixer -f /dev/mixer2 pcm2:mixer: at ? kld snd_uaudio (rec) $ If this is the default sound device, an attempt to change the default unit using mixer -d fails with a segfault because mod_dunit is called with a NULL device pointer, which is dereferenced to get the parent mixer. ctl_dunit seems to be a dummy, i.e., we don't actually need it and can simply pass the mixer to mod_dunit() directly. This patch removes that structure and associated indirection to fix the crash. Reviewed by: christos, hselasky MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D38060 --- usr.sbin/mixer/mixer.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/usr.sbin/mixer/mixer.c b/usr.sbin/mixer/mixer.c index e216efe3313c..6095f7550ea8 100644 --- a/usr.sbin/mixer/mixer.c +++ b/usr.sbin/mixer/mixer.c @@ -42,8 +42,8 @@ static void printall(struct mixer *, int); static void printminfo(struct mixer *, int); static void printdev(struct mixer *, int); static void printrecsrc(struct mixer *, int); /* XXX: change name */ +static int set_dunit(struct mixer *, int); /* Control handlers */ -static int mod_dunit(struct mix_dev *, void *); static int mod_volume(struct mix_dev *, void *); static int mod_mute(struct mix_dev *, void *); static int mod_recsrc(struct mix_dev *, void *); @@ -51,14 +51,6 @@ static int print_volume(struct mix_dev *, void *); static int print_mute(struct mix_dev *, void *); static int print_recsrc(struct mix_dev *, void *); -static const mix_ctl_t ctl_dunit = { - .parent_dev = NULL, - .id = -1, - .name = "default_unit", - .mod = mod_dunit, - .print = NULL -}; - int main(int argc, char *argv[]) { @@ -125,7 +117,7 @@ main(int argc, char *argv[]) initctls(m); - if (dflag && ctl_dunit.mod(m->dev, &dunit) < 0) + if (dflag && set_dunit(m, dunit) < 0) goto parse; if (sflag) { printrecsrc(m, oflag); @@ -316,20 +308,19 @@ printrecsrc(struct mixer *m, int oflag) } static int -mod_dunit(struct mix_dev *d, void *p) +set_dunit(struct mixer *m, int dunit) { - int dunit = *((int *)p); int n; if ((n = mixer_get_dunit()) < 0) { warn("cannot get default unit"); return (-1); } - if (mixer_set_dunit(d->parent_mixer, dunit) < 0) { + if (mixer_set_dunit(m, dunit) < 0) { warn("cannot set default unit to: %d", dunit); return (-1); } - printf("%s: %d -> %d\n", ctl_dunit.name, n, dunit); + printf("default_unit: %d -> %d\n", n, dunit); return (0); }