Subject: Re: mtod abuse?
To: Pavel Cahyna <pavel.cahyna@st.mff.cuni.cz>
From: Jason Thorpe <thorpej@wasabisystems.com>
List: tech-net
Date: 08/07/2004 09:44:18
--Apple-Mail-1--226774765
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII; format=flowed


On Aug 7, 2004, at 9:04 AM, Pavel Cahyna wrote:

> Hello,
>
> is it correct to call mtod() without calling m_pullup() before 
> dereferencing
> the pointer obtained? I would think that it isn't. Such calls do occur 
> in
> wi.c, function wi_start(), however. e.g.

It should be OK, as long as the code knows that the first mbuf in the 
chain contains all the data that is being referenced.

>
> --- cut here ---
> 			IF_DEQUEUE(&ic->ic_pwrsaveq, m0);
>                         wh = mtod(m0, struct ieee80211_frame *);
> 			llc = (struct llc *) (wh + 1);
> 			m_copydata(m0, 4, ETHER_ADDR_LEN * 2,
> 			    (caddr_t)&frmhdr.wi_ehdr);
> --->			frmhdr.wi_ehdr.ether_type = llc->llc_snap.ether_type;
> --- cut here ---
>
> or
>
> --- cut here ---
> 			IF_DEQUEUE(&ic->ic_mgtq, m0);
> 			m_copydata(m0, 4, ETHER_ADDR_LEN * 2,
> 			    (caddr_t)&frmhdr.wi_ehdr);
> 			frmhdr.wi_ehdr.ether_type = 0;
>                         wh = mtod(m0, struct ieee80211_frame *);
> --- cut here ---
>
> The arrow marks the point where I just saw a panic. Could this be the 
> cause?
>
> (Cc:-ing developers who are known to work on the wi driver, if you 
> find it
> inappropriate, feel free to protest loudly.)
>
> Thanks	Pavel
>
         -- Jason R. Thorpe <thorpej@wasabisystems.com>


--Apple-Mail-1--226774765
content-type: application/pgp-signature; x-mac-type=70674453;
	name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (Darwin)

iD8DBQFBFQbmOpVKkaBm8XkRAminAJ0TN9pnkCaus3L3gvU+7sWeICbFJgCeJalF
VI/gPskRkoy0basXZUoz0Zw=
=77gO
-----END PGP SIGNATURE-----

--Apple-Mail-1--226774765--