Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev minor clean ups:



details:   https://anonhg.NetBSD.org/src/rev/f9958246bad8
branches:  trunk
changeset: 822067:f9958246bad8
user:      mrg <mrg%NetBSD.org@localhost>
date:      Mon Feb 27 23:31:00 2017 +0000

description:
minor clean ups:
- mark a bunch of local things static
- export an explicit set of functions for audiobell, instead of hooking
  directly into the device callbacks, and avoid non-shared headers for
  the same prototypes
- s/audioprobe/audiomatch/
- use __func__

diffstat:

 sys/dev/audio.c     |  99 ++++++++++++++++++++++++++++++++--------------------
 sys/dev/audiobell.c |  18 +++-----
 sys/dev/audiovar.h  |   8 +++-
 3 files changed, 75 insertions(+), 50 deletions(-)

diffs (truncated from 338 to 300 lines):

diff -r eff9c27ab20b -r f9958246bad8 sys/dev/audio.c
--- a/sys/dev/audio.c   Mon Feb 27 21:48:34 2017 +0000
+++ b/sys/dev/audio.c   Mon Feb 27 23:31:00 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.313 2017/02/27 10:31:02 nat Exp $  */
+/*     $NetBSD: audio.c,v 1.314 2017/02/27 23:31:00 mrg Exp $  */
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsloss%yahoo.com.au@localhost>
@@ -148,7 +148,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.313 2017/02/27 10:31:02 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.314 2017/02/27 23:31:00 mrg Exp $");
 
 #include "audio.h"
 #if NAUDIO > 0
@@ -233,8 +233,8 @@
 int    audio_kqfilter(struct audio_chan *, struct knote *);
 paddr_t audiommap(dev_t, off_t, int, struct virtual_channel *);
 paddr_t audio_mmap(struct audio_softc *, off_t, int, struct virtual_channel *);
-int    audio_fop_mmap(struct file *, off_t *, size_t, int, int *, int *,
-                            struct uvm_object **, int *);
+static int audio_fop_mmap(struct file *, off_t *, size_t, int, int *, int *,
+                          struct uvm_object **, int *);
 
 int    mixer_open(dev_t, struct audio_softc *, int, int, struct lwp *,
                   struct file **);
@@ -315,12 +315,12 @@
 static int audio_sysctl_precision(SYSCTLFN_PROTO);
 static int audio_sysctl_channels(SYSCTLFN_PROTO);
 
-int    audioprobe(device_t, cfdata_t, void *);
-void   audioattach(device_t, device_t, void *);
-int    audiodetach(device_t, int);
-int    audioactivate(device_t, enum devact);
-void   audiochilddet(device_t, device_t);
-int    audiorescan(device_t, const char *, const int *);
+static int     audiomatch(device_t, cfdata_t, void *);
+static void    audioattach(device_t, device_t, void *);
+static int     audiodetach(device_t, int);
+static int     audioactivate(device_t, enum devact);
+static void    audiochilddet(device_t, device_t);
+static int     audiorescan(device_t, const char *, const int *);
 
 #ifdef AUDIO_PM_IDLE
 static void    audio_idle(void *);
@@ -348,13 +348,13 @@
 static int     audio_waitio(struct audio_softc *, kcondvar_t *,
                             struct virtual_channel *);
 
-int audioclose(struct file *);
-int audioread(struct file *, off_t *, struct uio *, kauth_cred_t, int);
-int audiowrite(struct file *, off_t *, struct uio *, kauth_cred_t, int);
-int audioioctl(struct file *, u_long, void *);
-int audiopoll(struct file *, int);
-int audiokqfilter(struct file *, struct knote *);
-int audiostat(struct file *, struct stat *);
+static int audioclose(struct file *);
+static int audioread(struct file *, off_t *, struct uio *, kauth_cred_t, int);
+static int audiowrite(struct file *, off_t *, struct uio *, kauth_cred_t, int);
+static int audioioctl(struct file *, u_long, void *);
+static int audiopoll(struct file *, int);
+static int audiokqfilter(struct file *, struct knote *);
+static int audiostat(struct file *, struct stat *);
 
 struct portname {
        const char *name;
@@ -413,9 +413,8 @@
 static int     null_fetcher_fetch_to(struct audio_softc *, stream_fetcher_t *,
                                      audio_stream_t *, int);
 
-int audiobellopen(dev_t, int, int, struct lwp *, struct file **);
-
-dev_type_open(audioopen);
+static dev_type_open(audioopen);
+/* XXXMRG use more dev_type_xxx */
 
 const struct cdevsw audio_cdevsw = {
        .d_open = audioopen,
@@ -460,23 +459,23 @@
                           22050, 16000, 11025, 8000, 4000 };
 
 CFATTACH_DECL3_NEW(audio, sizeof(struct audio_softc),
-    audioprobe, audioattach, audiodetach, audioactivate, audiorescan,
+    audiomatch, audioattach, audiodetach, audioactivate, audiorescan,
     audiochilddet, DVF_DETACH_SHUTDOWN);
 
 extern struct cfdriver audio_cd;
 
-int
-audioprobe(device_t parent, cfdata_t match, void *aux)
+static int
+audiomatch(device_t parent, cfdata_t match, void *aux)
 {
        struct audio_attach_args *sa;
 
        sa = aux;
-       DPRINTF(("audioprobe: type=%d sa=%p hw=%p\n",
-                sa->type, sa, sa->hwif));
+       DPRINTF(("%s: type=%d sa=%p hw=%p\n",
+                __func__, sa->type, sa, sa->hwif));
        return (sa->type == AUDIODEV_TYPE_AUDIO) ? 1 : 0;
 }
 
-void
+static void
 audioattach(device_t parent, device_t self, void *aux)
 {
        struct audio_softc *sc;
@@ -905,7 +904,7 @@
        audiorescan(self, "audio", NULL);
 }
 
-int
+static int
 audioactivate(device_t self, enum devact act)
 {
        struct audio_softc *sc = device_private(self);
@@ -924,7 +923,7 @@
        }
 }
 
-int
+static int
 audiodetach(device_t self, int flags)
 {
        struct audio_softc *sc;
@@ -1054,7 +1053,7 @@
        return 0;
 }
 
-void
+static void
 audiochilddet(device_t self, device_t child)
 {
 
@@ -1071,7 +1070,7 @@
        return 0;
 }
 
-int
+static int
 audiorescan(device_t self, const char *ifattr, const int *flags)
 {
        struct audio_softc *sc = device_private(self);
@@ -1552,6 +1551,7 @@
        return error;
 }
 
+/* Exported interfaces for audiobell. */
 int
 audiobellopen(dev_t dev, int flags, int ifmt, struct lwp *l,
              struct file **fp)
@@ -1574,7 +1574,30 @@
 
        return error;
 }
+
 int
+audiobellclose(struct file *fp)
+{
+
+       return audioclose(fp);
+}
+
+int
+audiobellwrite(struct file *fp, off_t *offp, struct uio *uio, kauth_cred_t cred,
+          int ioflag)
+{
+
+       return audiowrite(fp, offp, uio, cred, ioflag);
+}
+
+int
+audiobellioctl(struct file *fp, u_long cmd, void *addr)
+{
+
+       return audioioctl(fp, cmd, addr);
+}
+
+static int
 audioopen(dev_t dev, int flags, int ifmt, struct lwp *l)
 {
        struct audio_softc *sc;
@@ -1602,7 +1625,7 @@
        return error;
 }
 
-int
+static int
 audioclose(struct file *fp)
 {
        struct audio_softc *sc;
@@ -1643,7 +1666,7 @@
        return error;
 }
 
-int
+static int
 audioread(struct file *fp, off_t *offp, struct uio *uio, kauth_cred_t cred,
          int ioflag)
 {
@@ -1676,7 +1699,7 @@
        return error;
 }
 
-int
+static int
 audiowrite(struct file *fp, off_t *offp, struct uio *uio, kauth_cred_t cred,
           int ioflag)
 {
@@ -1709,7 +1732,7 @@
        return error;
 }
 
-int
+static int
 audioioctl(struct file *fp, u_long cmd, void *addr)
 {
        struct audio_softc *sc;
@@ -1762,7 +1785,7 @@
        return error;
 }
 
-int
+static int
 audiostat(struct file *fp, struct stat *st)
 {
        memset(st, 0, sizeof(*st));
@@ -1775,7 +1798,7 @@
        return 0;
 }
 
-int
+static int
 audiopoll(struct file *fp, int events)
 {
        struct audio_softc *sc;
@@ -1815,7 +1838,7 @@
        return revents;
 }
 
-int
+static int
 audiokqfilter(struct file *fp, struct knote *kn)
 {
        struct audio_softc *sc;
@@ -1853,7 +1876,7 @@
 }
 
 /* XXX:NS mmap is disabled. */
-int
+static int
 audio_fop_mmap(struct file *fp, off_t *offp, size_t len, int prot, int *flagsp,
             int *advicep, struct uvm_object **uobjp, int *maxprotp)
 {
diff -r eff9c27ab20b -r f9958246bad8 sys/dev/audiobell.c
--- a/sys/dev/audiobell.c       Mon Feb 27 21:48:34 2017 +0000
+++ b/sys/dev/audiobell.c       Mon Feb 27 23:31:00 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audiobell.c,v 1.15 2017/02/15 02:55:53 nat Exp $       */
+/*     $NetBSD: audiobell.c,v 1.16 2017/02/27 23:31:00 mrg Exp $       */
 
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include <sys/types.h>
-__KERNEL_RCSID(0, "$NetBSD: audiobell.c,v 1.15 2017/02/15 02:55:53 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audiobell.c,v 1.16 2017/02/27 23:31:00 mrg Exp $");
 
 #include <sys/audioio.h>
 #include <sys/conf.h>
@@ -48,13 +48,9 @@
 #include <sys/unistd.h>
 
 #include <dev/audio_if.h>
+#include <dev/audiovar.h>
 #include <dev/audiobellvar.h>
 
-extern int audiobellopen(dev_t, int, int, struct lwp *, struct file **);
-extern int audioclose(struct file *);
-extern int audiowrite(struct file *, off_t *, struct uio *, kauth_cred_t, int);
-extern int audioioctl(struct file *, u_long, void *);
-
 /* Convert a %age volume to an amount to add to u-law values */
 /* XXX Probably highly inaccurate -- should be regenerated */
 static const uint8_t volmap[] = {
@@ -159,8 +155,8 @@
        if (audiobellopen(audio, FWRITE, 0, NULL, &fp) != EMOVEFD || fp == NULL)
                return;
 
-       if (audioioctl(fp, AUDIO_GETINFO, &ai) != 0) {
-               audioclose(fp);
+       if (audiobellioctl(fp, AUDIO_GETINFO, &ai) != 0) {
+               audiobellclose(fp);
                return;



Home | Main Index | Thread Index | Old Index