NetBSD Problem Report #39110
From www@NetBSD.org Sun Jul 6 13:40:17 2008
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by narn.NetBSD.org (Postfix) with ESMTP id 24A5063BCE4
for <gnats-bugs@gnats.netbsd.org>; Sun, 6 Jul 2008 13:40:17 +0000 (UTC)
Message-Id: <20080706134016.EB04763B880@narn.NetBSD.org>
Date: Sun, 6 Jul 2008 13:40:16 +0000 (UTC)
From: paul@whooppee.com
Reply-To: paul@whooppee.com
To: gnats-bugs@NetBSD.org
Subject: Suspect typecast in src/sys/dev/ld.c
X-Send-Pr-Version: www-1.0
>Number: 39110
>Category: kern
>Synopsis: Suspect typecast in src/sys/dev/ld.c
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: kern-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Jul 06 13:45:00 +0000 2008
>Closed-Date: Sun Jul 06 14:26:45 +0000 2008
>Last-Modified: Sun Jul 06 14:26:45 +0000 2008
>Originator: Paul Goyette
>Release: 4.99.67
>Organization:
>Environment:
quicky:dev {285} uname -a
NetBSD quicky.whooppee.com 4.99.66 NetBSD 4.99.66 (QUICKY (ASUS M2N32 WS) 2008-06-20 03:02:36) #1: Fri Jun 20 04:58:08 PDT 2008 paul@speedy.whooppee.com:/build/obj/amd64/sys/arch/amd64/compile/QUICKY amd64
quicky:dev {286}
>Description:
In src/sys/dev/ld.c there is a typecast of a "struct device *" to a "struct ld_softc *". While this may work today due to fortuitous alignment of the structures, it is likely to cause problems in the future, especially if the "separate softc from device_t" project reaches this driver.
>How-To-Repeat:
Inspect the code
>Fix:
The following patch replaces the typecast with use of device_private(). Although it adds a couple of instructions, it's not on a commonly-used code path so will have negligible performance or memory-footprint impact.
Index: ld.c
===================================================================
RCS file: /build/cvsroot/src/sys/dev/ld.c,v
retrieving revision 1.59
diff -u -p -r1.59 ld.c
--- ld.c 11 Jun 2008 12:41:22 -0000 1.59
+++ ld.c 5 Jul 2008 15:28:47 -0000
@@ -915,6 +915,6 @@ ld_set_properties(struct ld_softc *ld)
static void
ld_config_interrupts (struct device *d)
{
- struct ld_softc *sc = (struct ld_softc *)d;
+ struct ld_softc *sc = (struct ld_softc *)device_private(d);
dkwedge_discover(&sc->sc_dk);
}
>Release-Note:
>Audit-Trail:
From: Quentin Garnier <cube@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/39110 CVS commit: src/sys/dev
Date: Sun, 6 Jul 2008 14:07:44 +0000 (UTC)
Module Name: src
Committed By: cube
Date: Sun Jul 6 14:07:44 UTC 2008
Modified Files:
src/sys/dev: ld.c
Log Message:
Use device_private() where appropriate.
Noted by Paul Goyette in PR#39110.
To generate a diff of this commit:
cvs rdiff -r1.59 -r1.60 src/sys/dev/ld.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->closed
State-Changed-By: cube@NetBSD.org
State-Changed-When: Sun, 06 Jul 2008 14:26:45 +0000
State-Changed-Why:
Considering that none of the ld drivers are "devcei_t-splitted", it didn't really
matter but changing it doesn't hurt.
Note that it's no longer necessary to cast: that's the whole idea, actually.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.