Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/dtv allocate memory for dtv_ts_section using kmem_al...



details:   https://anonhg.NetBSD.org/src/rev/331eefa9a1e1
branches:  trunk
changeset: 1010598:331eefa9a1e1
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Sat May 30 13:15:10 2020 +0000

description:
allocate memory for dtv_ts_section using kmem_alloc() in dtv_demux_read(),
instead of on-stack

XXX compile-tested only

diffstat:

 sys/dev/dtv/dtv_demux.c |  22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)

diffs (70 lines):

diff -r f6c8bff16ef5 -r 331eefa9a1e1 sys/dev/dtv/dtv_demux.c
--- a/sys/dev/dtv/dtv_demux.c   Sat May 30 12:36:37 2020 +0000
+++ b/sys/dev/dtv/dtv_demux.c   Sat May 30 13:15:10 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dtv_demux.c,v 1.10 2019/02/24 12:05:49 jmcneill Exp $ */
+/* $NetBSD: dtv_demux.c,v 1.11 2020/05/30 13:15:10 jdolecek Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -52,7 +52,7 @@
  */ 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dtv_demux.c,v 1.10 2019/02/24 12:05:49 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dtv_demux.c,v 1.11 2020/05/30 13:15:10 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -492,7 +492,7 @@
     kauth_cred_t cred, int flags)
 {
        struct dtv_demux *demux = fp->f_data;
-       struct dtv_ts_section sec;
+       struct dtv_ts_section *sec;
        int error;
 
        if (demux == NULL)
@@ -502,22 +502,25 @@
        if (demux->dd_mode != DTV_DEMUX_MODE_SECTION)
                return EIO;
 
+       sec = kmem_alloc(sizeof(*sec), KM_SLEEP);
+
        /* Wait for a complete PSI section */
        mutex_enter(&demux->dd_lock);
        while (demux->dd_secfilt.nsections == 0) {
                if (flags & IO_NDELAY) {
                        mutex_exit(&demux->dd_lock);
                        /* No data available */
-                       return EWOULDBLOCK;
+                       error = EWOULDBLOCK;
+                       goto out;
                }
                error = cv_wait_sig(&demux->dd_section_cv, &demux->dd_lock);
                if (error) {
                        mutex_exit(&demux->dd_lock);
-                       return error;
+                       goto out;
                }
        }
        /* Copy the completed PSI section */
-       sec = demux->dd_secfilt.section[demux->dd_secfilt.rp];
+       *sec = demux->dd_secfilt.section[demux->dd_secfilt.rp];
        /* Update read pointer */
        demux->dd_secfilt.rp++;
        if (demux->dd_secfilt.rp >= __arraycount(demux->dd_secfilt.section))
@@ -540,7 +543,12 @@
         * it should not be an issue as PSI sections have a max size of 4KB
         * (and callers will generally provide a big enough buffer).
         */
-       return uiomove(sec.sec_buf, sec.sec_length, uio);
+       error = uiomove(sec->sec_buf, sec->sec_length, uio);
+
+out:
+       kmem_free(sec, sizeof(*sec));
+       return error;
+       
 }
 
 /*



Home | Main Index | Thread Index | Old Index