public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Matthias Schiffer <mschiffer@universe-factory.net>
To: Antonio Quartulli <antonio@meshcoding.com>
Cc: The list for a Better Approach To Mobile Ad-hoc Networking
	<b.a.t.m.a.n@lists.open-mesh.org>
Subject: Re: [B.A.T.M.A.N.] [PATCH] batman-adv: add compat code for kstrtou32
Date: Thu, 21 Nov 2013 15:31:23 +0100	[thread overview]
Message-ID: <528E193B.3070701@universe-factory.net> (raw)
In-Reply-To: <20131121142010.GE311@neomailbox.net>

[-- Attachment #1: Type: text/plain, Size: 1335 bytes --]

On 11/21/2013 03:20 PM, Antonio Quartulli wrote:
> On Thu, Nov 21, 2013 at 02:57:50PM +0100, Matthias Schiffer wrote:
>> On 11/21/2013 08:21 AM, Antonio Quartulli wrote:
>>> On Thu, Nov 21, 2013 at 04:45:14AM +0100, Matthias Schiffer wrote:
>>>> You are casting a u32 * to unsigned long *? Won't this break horribly
>>>> when sizeof(u32) != sizeof(unsigned long)?
>>>>
>>>
>>> It will break when sizeof(unsigned long) > sizeof(uint32). For example on
>>> x86_64. Hopefully nobody would use such ancient kernel on his machine. But you
>>> are right.
>>>
>>> What do you think of the attached patch?
>>>
>>
>> That's better, but if you care about overflow, you should add something like
>>
>> if (_v != (unsigned long)v)
>> 	_r = -ERANGE;
> 
> yeah, thanks! I'll add this!
> 
>>
>> Also, the comment in the line above doesn't make sense anymore...
> 
> yeah, I removed that already.
> 
> 

Ah, and I overlooked that you have to dereference v and take the address
of _v; adding parantheses around the parameters might also be a good
idea as it is a macro.

So I'd recommend something like this (not even compile tested...):

({\
	unsigned long _v;\
	int _r;\
	_r = strict_strtoul((cp), (base), &_v);\
	if (_v == (unsigned long)(u32)_v)\
		*(v) = (u32)_v;\
	else\
		_r = -ERANGE;\
	_r;\
})



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

  reply	other threads:[~2013-11-21 14:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-19  7:26 [B.A.T.M.A.N.] [PATCH] batman-adv: add compat code for kstrtou32 Antonio Quartulli
2013-11-21  1:20 ` Marek Lindner
2013-11-21  3:45 ` Matthias Schiffer
2013-11-21  7:21   ` Antonio Quartulli
2013-11-21 13:57     ` Matthias Schiffer
2013-11-21 14:20       ` Antonio Quartulli
2013-11-21 14:31         ` Matthias Schiffer [this message]
2013-11-21 14:40           ` Antonio Quartulli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=528E193B.3070701@universe-factory.net \
    --to=mschiffer@universe-factory.net \
    --cc=antonio@meshcoding.com \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox