From: Johannes Berg <[email protected]>
Alexander reported a strange crash in iwlagn that
Meenakshi and Wey couldn't reproduce. I just ran
into the same issue and tracked it down to stack
corruption. This fixes it.
The problem was introduced in
commit 4b8b99b6e650d0527f3a123744b7459976581d14
Author: Wey-Yi Guy <[email protected]>
Date: Fri Jul 8 14:29:48 2011 -0700
iwlagn: radio sensor offset in le16 format
Cc: Wey-Yi Guy <[email protected]>
Cc: Meenakshi Venkataraman <[email protected]>
Reported-by: Alexander Diewald <[email protected]>
Signed-off-by: Johannes Berg <[email protected]>
---
Wey, please fix your recent commit in our internal tree
that does the v2 offset calibration -- it has the same
bug twice.
drivers/net/wireless/iwlwifi/iwl-agn-ucode.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c 2011-09-12 21:01:34.000000000 +0200
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c 2011-09-12 21:01:43.000000000 +0200
@@ -167,7 +167,7 @@ static int iwlagn_set_temperature_offset
memset(&cmd, 0, sizeof(cmd));
iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD);
- memcpy(&cmd.radio_sensor_offset, offset_calib, sizeof(offset_calib));
+ memcpy(&cmd.radio_sensor_offset, offset_calib, sizeof(*offset_calib));
if (!(cmd.radio_sensor_offset))
cmd.radio_sensor_offset = DEFAULT_RADIO_SENSOR_OFFSET;
On Mon, 2011-09-12 at 12:14 -0700, Daniel Halperin wrote:
> On Mon, Sep 12, 2011 at 12:08 PM, Johannes Berg
> <[email protected]> wrote:
> >
> > --- a/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c 2011-09-12 21:01:34.000000000 +0200
> > +++ b/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c 2011-09-12 21:01:43.000000000 +0200
> > @@ -167,7 +167,7 @@ static int iwlagn_set_temperature_offset
> >
> > memset(&cmd, 0, sizeof(cmd));
> > iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD);
> > - memcpy(&cmd.radio_sensor_offset, offset_calib, sizeof(offset_calib));
> > + memcpy(&cmd.radio_sensor_offset, offset_calib, sizeof(*offset_calib));
> > if (!(cmd.radio_sensor_offset))
> > cmd.radio_sensor_offset = DEFAULT_RADIO_SENSOR_OFFSET;
>
> Nice catch!
>
> This kinda bug seems ideal for Julia Lawall's stuff to catch, doesn't it?
>
> Right: memcpy(addr, obj, sizeof(*obj))
> Wrong: memcpy(addr, obj, sizeof(obj))
>
Thank you very much for catch my mistake
Wey
On Mon, Sep 12, 2011 at 12:08 PM, Johannes Berg
<[email protected]> wrote:
>
> --- a/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c ? ? ?2011-09-12 21:01:34.000000000 +0200
> +++ b/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c ? ? ?2011-09-12 21:01:43.000000000 +0200
> @@ -167,7 +167,7 @@ static int iwlagn_set_temperature_offset
>
> ? ? ? ?memset(&cmd, 0, sizeof(cmd));
> ? ? ? ?iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD);
> - ? ? ? memcpy(&cmd.radio_sensor_offset, offset_calib, sizeof(offset_calib));
> + ? ? ? memcpy(&cmd.radio_sensor_offset, offset_calib, sizeof(*offset_calib));
> ? ? ? ?if (!(cmd.radio_sensor_offset))
> ? ? ? ? ? ? ? ?cmd.radio_sensor_offset = DEFAULT_RADIO_SENSOR_OFFSET;
Nice catch!
This kinda bug seems ideal for Julia Lawall's stuff to catch, doesn't it?
Right: memcpy(addr, obj, sizeof(*obj))
Wrong: memcpy(addr, obj, sizeof(obj))
Dan
On Mon, 2011-09-12 at 12:14 -0700, Daniel Halperin wrote:
> On Mon, Sep 12, 2011 at 12:08 PM, Johannes Berg
> <[email protected]> wrote:
> >
> > --- a/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c 2011-09-12 21:01:34.000000000 +0200
> > +++ b/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c 2011-09-12 21:01:43.000000000 +0200
> > @@ -167,7 +167,7 @@ static int iwlagn_set_temperature_offset
> >
> > memset(&cmd, 0, sizeof(cmd));
> > iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD);
> > - memcpy(&cmd.radio_sensor_offset, offset_calib, sizeof(offset_calib));
> > + memcpy(&cmd.radio_sensor_offset, offset_calib, sizeof(*offset_calib));
> > if (!(cmd.radio_sensor_offset))
> > cmd.radio_sensor_offset = DEFAULT_RADIO_SENSOR_OFFSET;
>
> Nice catch!
>
> This kinda bug seems ideal for Julia Lawall's stuff to catch, doesn't it?
>
> Right: memcpy(addr, obj, sizeof(*obj))
> Wrong: memcpy(addr, obj, sizeof(obj))
That thought occurred to me as well, but I had been debugging until late
at night so didn't even try to write a script to flag this. :)
johannes
SGkgSm9oYW5uZXMsDQoNCkkndmUganVzdCB0cmllZCB0aGUgZml4IGFuZCBpdCB3b3Jrcy4gSSBz
d2l0Y2hlZCBvZmYgYWxsIHRoZSBkZWJ1Z2dpbmcgb3B0aW9ucyBpbiB0aGUgaXdsd2lmaSBkcml2
ZXIgYW5kIHRoZSB3aXJlbGVzcyBzdGFjayBhbmQgdHVybmVkIG9mZiB0aGUgZnJhbWUgcG9pbnRl
cnMgZm9yIHRlc3RpbmcuDQpUaGFuayB5b3UgdmVyeSBtdWNoLiANCg0KSnVzdCBzb21lIGZpbmFs
IG5vdGVzOg0KVGhhbmsgeW91IFdleSwgZm9yIGV2ZW4gZm9yd2FyZGluZyB0aGlzIGlzc3VlIHdo
ZW4geW91IHdlcmUgb24gdmFjYXRpb24hDQpBbHNvLCBzcGVjaWFsIFRoYW5rcyB0byB5b3UsIE1l
ZW5ha3NoaSwgZm9yIHRha2luZyB0aGF0IG11Y2ggdGltZS4gSSBhbHNvIGxlYXJuZWQgYSBsb3Qg
cmVnYXJkaW5nIGtlcm5lbCBkZWJ1Z2dpbmcgKG5ldGNv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2V0X2NhbGliKSk7DQo+ICsJbWVtY3B5KCZjbWQucmFkaW9fc2Vuc29yX29mZnNldCwgb2Zmc2V0
X2NhbGliLCBzaXplb2YoKm9mZnNldF9jYWxpYikpOw0KPiAgCWlmICghKGNtZC5yYWRpb19zZW5z
b3Jfb2Zmc2V0KSkNCj4gIAkJY21kLnJhZGlvX3NlbnNvcl9vZmZzZXQgPSBERUZBVUxUX1JBRElP
X1NFTlNPUl9PRkZTRVQ7DQo=
On Mon, 12 Sep 2011, Daniel Halperin wrote:
> On Mon, Sep 12, 2011 at 12:08 PM, Johannes Berg
> <[email protected]> wrote:
> >
> > --- a/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c ? ? ?2011-09-12 21:01:34.000000000 +0200
> > +++ b/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c ? ? ?2011-09-12 21:01:43.000000000 +0200
> > @@ -167,7 +167,7 @@ static int iwlagn_set_temperature_offset
> >
> > ? ? ? ?memset(&cmd, 0, sizeof(cmd));
> > ? ? ? ?iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD);
> > - ? ? ? memcpy(&cmd.radio_sensor_offset, offset_calib, sizeof(offset_calib));
> > + ? ? ? memcpy(&cmd.radio_sensor_offset, offset_calib, sizeof(*offset_calib));
> > ? ? ? ?if (!(cmd.radio_sensor_offset))
> > ? ? ? ? ? ? ? ?cmd.radio_sensor_offset = DEFAULT_RADIO_SENSOR_OFFSET;
>
> Nice catch!
>
> This kinda bug seems ideal for Julia Lawall's stuff to catch, doesn't it?
>
> Right: memcpy(addr, obj, sizeof(*obj))
> Wrong: memcpy(addr, obj, sizeof(obj))
Yes... I have tried in the past the following:
x = <+... sizeof(x) ...+>
But that doesn't catch the above because there is no return value. I will
try it.
julia