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] [day] [month] [year] [list]
Message-ID: <CAC5umyhPzvAhX8Y-oa5Kr-G7ZAJ15HV_H2HMgxrV2KZUJadsNw@mail.gmail.com>
Date:	Thu, 24 May 2012 20:54:16 +0900
From:	Akinobu Mita <akinobu.mita@...il.com>
To:	Matthew Wilcox <matthew@....cx>
Cc:	Jan Kara <jack@...e.cz>, linux-kernel@...r.kernel.org,
	akpm@...ux-foundation.org, Anders Larsen <al@...rsen.net>,
	Alasdair Kergon <agk@...hat.com>, dm-devel@...hat.com,
	linux-fsdevel@...r.kernel.org,
	Laurent Pinchart <laurent.pinchart@...asonboard.com>,
	linux-media@...r.kernel.org, Mark Fasheh <mfasheh@...e.com>,
	Joel Becker <jlbec@...lplan.org>, ocfs2-devel@....oracle.com,
	linux-ext4@...r.kernel.org,
	Andreas Dilger <adilger.kernel@...ger.ca>,
	"Theodore Ts'o" <tytso@....edu>
Subject: Re: [PATCH 01/10] string: introduce memweight

2012/5/23 Matthew Wilcox <matthew@....cx>:
> On Wed, May 23, 2012 at 09:12:18PM +0900, Akinobu Mita wrote:
>> size_t memweight(const void *ptr, size_t bytes)
>
> Why should this return size_t instead of unsigned long?

I just use the same type as the bytes argument without mature
consideration.  If unsigned long is better than size_t, I'll
change the return type.

>> {
>>       size_t w = 0;
>>       size_t longs;
>>       const unsigned char *bitmap = ptr;
>>
>>       for (; bytes > 0 && ((unsigned long)bitmap) % sizeof(long);
>>                       bytes--, bitmap++)
>>               w += hweight8(*bitmap);
>>
>>       longs = bytes / sizeof(long);
>>       BUG_ON(longs >= INT_MAX / BITS_PER_LONG);
>>       w += bitmap_weight((unsigned long *)bitmap, longs * BITS_PER_LONG);
>>       bytes -= longs * sizeof(long);
>>       bitmap += longs * sizeof(long);
>>
>>       for (; bytes > 0; bytes--, bitmap++)
>>               w += hweight8(*bitmap);
>>
>>       return w;
>> }
>
> bitmap_weight copes with a bitmask that isn't a multiple of BITS_PER_LONG
> in size already.  So I think this can be done as:
>
> unsigned long memweight(const void *s, size_t n)
> {
>        const unsigned char *ptr = s;
>        unsigned long r = 0;
>
>        while (n > 0 && (unsigned long)ptr % sizeof(long)) {
>                r += hweight8(*ptr);
>                n--;
>                ptr++;
>        }
>
>        BUG_ON(n >= INT_MAX / 8)
>
>        return r + bitmap_weight((unsigned long *)ptr, n * 8);
> }

This works perfectly on little-endian machines.  But it doesn't work
on big-endian machines, if the bottom edge of memory area is not
aligned on long word boundary.
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ