Subject: Re: hpckbd vs. -Wcast-qual
To: None <tech-kern@NetBSD.org>
From: Peter Postma <peter@pointless.nl>
List: tech-kern
Date: 07/12/2006 01:27:57
--OXfL5xGRrasGEqWY
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Mon, Jun 26, 2006 at 11:53:59PM +0400, Valeriy E. Ushakov wrote:
> 
> I think that pckbd_keydesctab[] was constified incorrectly.  Preceding
> commetns says:
> 
> /* KBD_NULLMAP generates a entry for machine native variant.
>    the entry will be modified by machine dependent keyboard driver. */
>    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> So the right fix is to unconst the array.
> 

Ok, I did this and added an extra comment, see attachment.
Would this be ok to commit?

-- 
Peter Postma

--OXfL5xGRrasGEqWY
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="pckbd_keydesctab.diff"

Index: hpc/hpckbd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/hpc/hpckbd.c,v
retrieving revision 1.17
diff -u -r1.17 hpckbd.c
--- hpc/hpckbd.c	29 Mar 2006 06:37:35 -0000	1.17
+++ hpc/hpckbd.c	11 Jul 2006 23:23:14 -0000
@@ -267,15 +267,7 @@
 	int i;
 	struct wscons_keydesc *desc;
 
-	/* fix keydesc table */
-	/* 
-	 * XXX The way this is done is really wrong.  The __UNCONST()
-	 * is a hint as to what is wrong.  This actually ends up modifying
-	 * initialized data which is marked "const".
-	 * The reason we get away with it here is apparently that text
-	 * and read-only data gets mapped read/write on the platforms
-	 * using this code.
-	 */
+	/* fix keydesc table, the UNCONST is "OK". */
 	desc = (struct wscons_keydesc *)__UNCONST(hpckbd_keymapdata.keydesc);
 	for (i = 0; desc[i].name != 0; i++) {
 		if ((desc[i].name & KB_MACHDEP) && desc[i].map == NULL) {

Index: pckbport/wskbdmap_mfii.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pckbport/wskbdmap_mfii.c,v
retrieving revision 1.11
diff -u -r1.11 wskbdmap_mfii.c
--- pckbport/wskbdmap_mfii.c	1 Apr 2006 23:02:32 -0000	1.11
+++ pckbport/wskbdmap_mfii.c	11 Jul 2006 23:23:15 -0000
@@ -551,7 +551,8 @@
    the entry will be modified by machine dependent keyboard driver. */
 #define KBD_NULLMAP(name, base) { name, base, 0, 0 }
 
-const struct wscons_keydesc pckbd_keydesctab[] = {
+/* This array is intentionally not const, see above comment. */
+struct wscons_keydesc pckbd_keydesctab[] = {
 	KBD_MAP(KB_US,			0,	pckbd_keydesc_us),
 #ifndef WSKBD_USONLY
 	KBD_MAP(KB_DE,			KB_US,	pckbd_keydesc_de),

Index: pckbport/wskbdmap_mfii.h
===================================================================
RCS file: /cvsroot/src/sys/dev/pckbport/wskbdmap_mfii.h,v
retrieving revision 1.2
diff -u -r1.2 wskbdmap_mfii.h
--- pckbport/wskbdmap_mfii.h	11 Dec 2005 12:23:22 -0000	1.2
+++ pckbport/wskbdmap_mfii.h	11 Jul 2006 23:23:15 -0000
@@ -36,4 +36,4 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-extern const struct wscons_keydesc pckbd_keydesctab[];
+extern struct wscons_keydesc pckbd_keydesctab[];

--OXfL5xGRrasGEqWY--