git: ddc8576d2979 - main - fb: Explicitly handle errors when getting or setting a colour palette

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Wed, 27 Dec 2023 00:06:17 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=ddc8576d297937a1395f47550a8f5b1fac79afc2

commit ddc8576d297937a1395f47550a8f5b1fac79afc2
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2023-12-27 00:00:14 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-12-27 00:01:26 +0000

    fb: Explicitly handle errors when getting or setting a colour palette
    
    In the VESA driver, simply ignore errors.  It is not clear to me how to
    return them to userspace.
    
    This is in preparation for annotating copyin() and related functions
    with __result_use_check.
    
    MFC after:      1 week
---
 sys/dev/fb/vesa.c | 16 ++++++++--------
 sys/dev/fb/vga.c  | 24 ++++++++++++++++--------
 2 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/sys/dev/fb/vesa.c b/sys/dev/fb/vesa.c
index ee3409dfa755..e1cca3a70725 100644
--- a/sys/dev/fb/vesa.c
+++ b/sys/dev/fb/vesa.c
@@ -1698,12 +1698,12 @@ get_palette(video_adapter_t *adp, int base, int count,
 	b = g + count;
 	error = vesa_bios_save_palette2(base, count, r, g, b, bits);
 	if (error == 0) {
-		copyout(r, red, count);
-		copyout(g, green, count);
-		copyout(b, blue, count);
+		(void)copyout(r, red, count);
+		(void)copyout(g, green, count);
+		(void)copyout(b, blue, count);
 		if (trans != NULL) {
 			bzero(r, count);
-			copyout(r, trans, count);
+			(void)copyout(r, trans, count);
 		}
 	}
 	free(r, M_DEVBUF);
@@ -1729,12 +1729,12 @@ set_palette(video_adapter_t *adp, int base, int count,
 		return (1);
 
 	bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
-	r = malloc(count * 3, M_DEVBUF, M_WAITOK);
+	r = malloc(count * 3, M_DEVBUF, M_WAITOK | M_ZERO);
 	g = r + count;
 	b = g + count;
-	copyin(red, r, count);
-	copyin(green, g, count);
-	copyin(blue, b, count);
+	(void)copyin(red, r, count);
+	(void)copyin(green, g, count);
+	(void)copyin(blue, b, count);
 
 	error = vesa_bios_load_palette2(base, count, r, g, b, bits);
 	free(r, M_DEVBUF);
diff --git a/sys/dev/fb/vga.c b/sys/dev/fb/vga.c
index eb081ae533d7..9851838aa8f3 100644
--- a/sys/dev/fb/vga.c
+++ b/sys/dev/fb/vga.c
@@ -2854,6 +2854,7 @@ get_palette(video_adapter_t *adp, int base, int count,
     u_char *r;
     u_char *g;
     u_char *b;
+    int error;
 
     if (count < 0 || base < 0 || count > 256 || base > 256 ||
 	base + count > 256)
@@ -2863,19 +2864,26 @@ get_palette(video_adapter_t *adp, int base, int count,
     g = r + count;
     b = g + count;
     if (vga_save_palette2(adp, base, count, r, g, b)) {
-	free(r, M_DEVBUF);
-	return ENODEV;
-    }
-    copyout(r, red, count);
-    copyout(g, green, count);
-    copyout(b, blue, count);
+	error = ENODEV;
+	goto out;
+    }
+    error = copyout(r, red, count);
+    if (error != 0)
+	goto out;
+    error = copyout(g, green, count);
+    if (error != 0)
+	goto out;
+    error = copyout(b, blue, count);
+    if (error != 0)
+	goto out;
     if (trans != NULL) {
 	bzero(r, count);
-	copyout(r, trans, count);
+	error = copyout(r, trans, count);
     }
+out:
     free(r, M_DEVBUF);
 
-    return 0;
+    return error;
 }
 
 static int