Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/rasops Fix unaligned writes to buffer, that are intr...



details:   https://anonhg.NetBSD.org/src/rev/cc6e7ce98263
branches:  trunk
changeset: 458590:cc6e7ce98263
user:      rin <rin%NetBSD.org@localhost>
date:      Fri Aug 02 04:22:04 2019 +0000

description:
Fix unaligned writes to buffer, that are introduced in 1.105:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/dev/rasops/rasops.c#rev1.105

diffstat:

 sys/dev/rasops/rasops.c |  38 +++++++++-----------------------------
 1 files changed, 9 insertions(+), 29 deletions(-)

diffs (71 lines):

diff -r e64999690bd0 -r cc6e7ce98263 sys/dev/rasops/rasops.c
--- a/sys/dev/rasops/rasops.c   Fri Aug 02 04:18:15 2019 +0000
+++ b/sys/dev/rasops/rasops.c   Fri Aug 02 04:22:04 2019 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: rasops.c,v 1.106 2019/08/02 04:18:15 rin Exp $        */
+/*      $NetBSD: rasops.c,v 1.107 2019/08/02 04:22:04 rin Exp $        */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.106 2019/08/02 04:18:15 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.107 2019/08/02 04:22:04 rin Exp $");
 
 #include "opt_rasops.h"
 #include "rasops_glue.h"
@@ -1124,8 +1124,8 @@
 rasops_erasecols(void *cookie, int row, int col, int num, long attr)
 {
        struct rasops_info *ri = (struct rasops_info *)cookie;
-       void *buf = ri->ri_buf;
-       int height, cnt, slop1, slop2, clr;
+       uint32_t *buf = ri->ri_buf;
+       int height, cnt, clr;
        uint32_t *dp, *rp, *hp;
 
        hp = NULL;      /* XXX GCC */
@@ -1156,36 +1156,16 @@
 
        dp = buf;
 
-       slop1 = (4 - ((uintptr_t)rp & 3)) & 3;
-       slop2 = (num - slop1) & 3;
-       num = (num - slop1 /* - slop2 */) >> 2;
+       /* Write 4 bytes per loop */
+       for (cnt = num >> 2; cnt; cnt--)
+               *dp++ = clr;
 
-       /* Align span to 4 bytes */
-       if (slop1 & 1) {
+       /* Write unaligned trailing slop */
+       for (cnt = num & 3; cnt; cnt--) {
                *(uint8_t *)dp = clr;
                DELTA(dp, 1, uint32_t *);
        }
 
-       if (slop1 & 2) {
-               *(uint16_t *)dp = clr;
-               DELTA(dp, 2, uint32_t *);
-       }
-
-       /* Write 4 bytes per loop */
-       for (cnt = num; cnt; cnt--)
-               *dp++ = clr;
-
-       /* Write unaligned trailing slop */
-       if (slop2 & 1) {
-               *(uint8_t *)dp = clr;
-               DELTA(dp, 1, uint32_t *);
-       }
-
-       if (slop2 & 2)
-               *(uint16_t *)dp = clr;
-
-       num = slop1 + (num << 2) + slop2;
-
        while (height--) {
                memcpy(rp, buf, num);
                DELTA(rp, ri->ri_stride, uint32_t *);



Home | Main Index | Thread Index | Old Index