Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci reduce stack usage in radeonfb_pickres() and rad...



details:   https://anonhg.NetBSD.org/src/rev/a75f2d27466a
branches:  trunk
changeset: 934394:a75f2d27466a
user:      macallan <macallan%NetBSD.org@localhost>
date:      Thu Jun 11 07:46:59 2020 +0000

description:
reduce stack usage in radeonfb_pickres() and radeonfb_set_cursor()

diffstat:

 sys/dev/pci/radeonfb.c |  65 +++++++++++++++++++++++++++----------------------
 1 files changed, 36 insertions(+), 29 deletions(-)

diffs (145 lines):

diff -r d78b49acd502 -r a75f2d27466a sys/dev/pci/radeonfb.c
--- a/sys/dev/pci/radeonfb.c    Thu Jun 11 05:16:22 2020 +0000
+++ b/sys/dev/pci/radeonfb.c    Thu Jun 11 07:46:59 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: radeonfb.c,v 1.106 2020/02/06 13:31:30 macallan Exp $ */
+/*     $NetBSD: radeonfb.c,v 1.107 2020/06/11 07:46:59 macallan Exp $ */
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: radeonfb.c,v 1.106 2020/02/06 13:31:30 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: radeonfb.c,v 1.107 2020/06/11 07:46:59 macallan Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -80,6 +80,7 @@
 #include <sys/kernel.h>
 #include <sys/lwp.h>
 #include <sys/kauth.h>
+#include <sys/kmem.h>
 
 #include <dev/wscons/wsdisplayvar.h>
 #include <dev/wscons/wsconsio.h>
@@ -3694,12 +3695,12 @@
        unsigned        index, count;
        int             i, err;
        int             pitch, size;
-       struct radeonfb_cursor  nc;
+       struct radeonfb_cursor  *nc = &dp->rd_tempcursor;
 
        flags = wc->which;
 
        /* copy old values */
-       nc = dp->rd_cursor;
+       memcpy(nc, &dp->rd_cursor, sizeof(struct radeonfb_cursor));
 
        if (flags & WSDISPLAY_CURSOR_DOCMAP) {
                index = wc->cmap.index;
@@ -3719,7 +3720,7 @@
                        return err;
 
                for (i = index; i < index + count; i++) {
-                       nc.rc_cmap[i] =
+                       nc->rc_cmap[i] =
                            (r[i] << 16) + (g[i] << 8) + (b[i] << 0);
                }
        }
@@ -3734,46 +3735,46 @@
                size = pitch * wc->size.y;
 
                /* clear the old cursor and mask */
-               memset(nc.rc_image, 0, 512);
-               memset(nc.rc_mask, 0, 512);
-
-               nc.rc_size = wc->size;
-
-               if ((err = copyin(wc->image, nc.rc_image, size)) != 0)
+               memset(nc->rc_image, 0, 512);
+               memset(nc->rc_mask, 0, 512);
+
+               nc->rc_size = wc->size;
+
+               if ((err = copyin(wc->image, nc->rc_image, size)) != 0)
                        return err;
 
-               if ((err = copyin(wc->mask, nc.rc_mask, size)) != 0)
+               if ((err = copyin(wc->mask, nc->rc_mask, size)) != 0)
                        return err;
        }
 
        if (flags & WSDISPLAY_CURSOR_DOHOT) {
-               nc.rc_hot = wc->hot;
-               if (nc.rc_hot.x >= nc.rc_size.x)
-                       nc.rc_hot.x = nc.rc_size.x - 1;
-               if (nc.rc_hot.y >= nc.rc_size.y)
-                       nc.rc_hot.y = nc.rc_size.y - 1;
+               nc->rc_hot = wc->hot;
+               if (nc->rc_hot.x >= nc->rc_size.x)
+                       nc->rc_hot.x = nc->rc_size.x - 1;
+               if (nc->rc_hot.y >= nc->rc_size.y)
+                       nc->rc_hot.y = nc->rc_size.y - 1;
        }
 
        if (flags & WSDISPLAY_CURSOR_DOPOS) {
-               nc.rc_pos = wc->pos;
-               if (nc.rc_pos.x >= dp->rd_virtx)
-                       nc.rc_pos.x = dp->rd_virtx - 1;
+               nc->rc_pos = wc->pos;
+               if (nc->rc_pos.x >= dp->rd_virtx)
+                       nc->rc_pos.x = dp->rd_virtx - 1;
 #if 0
-               if (nc.rc_pos.x < 0)
-                       nc.rc_pos.x = 0;
+               if (nc->rc_pos.x < 0)
+                       nc->rc_pos.x = 0;
 #endif
-               if (nc.rc_pos.y >= dp->rd_virty)
-                       nc.rc_pos.y = dp->rd_virty - 1;
+               if (nc->rc_pos.y >= dp->rd_virty)
+                       nc->rc_pos.y = dp->rd_virty - 1;
 #if 0
-               if (nc.rc_pos.y < 0)
-                       nc.rc_pos.y = 0;
+               if (nc->rc_pos.y < 0)
+                       nc->rc_pos.y = 0;
 #endif
        }
        if (flags & WSDISPLAY_CURSOR_DOCUR) {
-               nc.rc_visible = wc->enable;
+               nc->rc_visible = wc->enable;
        }
 
-       dp->rd_cursor = nc;
+       memcpy(&dp->rd_cursor, nc, sizeof(struct radeonfb_cursor));
        radeonfb_cursor_update(dp, wc->which);
 
        return 0;
@@ -4174,10 +4175,14 @@
                }
 
        } else {
-               struct videomode        modes[64];
+               struct videomode        *modes;
+               size_t                  smodes;
                int                     nmodes = 0;
                int                     valid = 0;
 
+               smodes = sizeof(struct videomode) * 64;
+               modes = kmem_alloc(smodes, KM_SLEEP);
+
                for (i = 0; i < dp->rd_ncrtcs; i++) {
                        /*
                         * pick the largest resolution in common.
@@ -4246,6 +4251,8 @@
                                *y = modes[i].vdisplay;
                        }
                }
+               kmem_free(modes, smodes);
+
        }
 
        if ((*x == 0) || (*y == 0)) {



Home | Main Index | Thread Index | Old Index