lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Sat, 12 Sep 2009 22:41:57 +0800
From:	Wu Fengguang <fengguang.wu@...el.com>
To:	Andrew Morton <akpm@...ux-foundation.org>
Cc:	"mtosatti@...hat.com" <mtosatti@...hat.com>,
	"gregkh@...e.de" <gregkh@...e.de>,
	"broonie@...nsource.wolfsonmicro.com" 
	<broonie@...nsource.wolfsonmicro.com>,
	"johannes@...solutions.net" <johannes@...solutions.net>,
	"avi@...ranet.com" <avi@...ranet.com>,
	"andi@...stfloor.org" <andi@...stfloor.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 2/3] devmem: introduce size_inside_page()

On Sat, Sep 12, 2009 at 07:55:43AM +0800, Andrew Morton wrote:
> On Fri, 11 Sep 2009 10:23:35 +0800
> Wu Fengguang <fengguang.wu@...el.com> wrote:
> 
> > Introduce size_inside_page() to replace duplicate /dev/mem code.
> > 
> > Also apply it to /dev/kmem, whose alignment logic was buggy.
> > 
> > 
> > CC: Marcelo Tosatti <mtosatti@...hat.com>
> > CC: Greg Kroah-Hartman <gregkh@...e.de>
> > CC: Mark Brown <broonie@...nsource.wolfsonmicro.com>
> > CC: Johannes Berg <johannes@...solutions.net>
> > CC: Avi Kivity <avi@...ranet.com>
> > Signed-off-by: Wu Fengguang <fengguang.wu@...el.com>
> > ---
> >  drivers/char/mem.c |   60 +++++++++++++------------------------------
> >  1 file changed, 19 insertions(+), 41 deletions(-)
> > 
> > --- linux.orig/drivers/char/mem.c
> > +++ linux/drivers/char/mem.c
> > @@ -35,6 +35,19 @@
> >  # include <linux/efi.h>
> >  #endif
> >  
> > +static inline unsigned long size_inside_page(unsigned long start,
> > +					     unsigned long size)
> > +{
> > +	unsigned long sz;
> > +
> > +	if (-start & (PAGE_SIZE - 1))
> > +		sz = -start & (PAGE_SIZE - 1);
> 
> What on earth is this doing?  Negating an unsigned number?
> 
> Can we get rid of these party tricks and use something more
> conventional here?  In a separate patch I guess.

OK. See the followed patches.

> > +	else
> > +		sz = PAGE_SIZE;
> > +
> > +	return min_t(unsigned long, sz, size);
> 
> Can use min() here.

Done.

> > +}
> 
> Please have a think about the types.  Should we be using unsigned long,
> or size_t?  Which makes more sense?  Which maps better onto reality?
> 
> I suspect that the min_t which you inherited was added somewhere
> because someone didn't get the types right: int-vs-size_t or something.
> If we actually get the types right, this sort of thing goes away.

I tend to just use unsigned long because even though the value itself
is small, it will be elevated to unsigned long in majority use cases.

Does that make sense?

> 
> > @@ -462,10 +451,8 @@ static ssize_t read_kmem(struct file *fi
> >  		if (!kbuf)
> >  			return -ENOMEM;
> >  		while (count > 0) {
> > -			int len = count;
> > +			int len = size_inside_page(p, count);
> 
> int?

Err, changed it to unsigned long sz.

Thanks,
Fengguang
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ