Re: [PATCH] random: check for increase of entropy_count because of signed conversion

2014-07-19 Thread Hannes Frederic Sowa
On Sa, 2014-07-19 at 01:42 -0400, Theodore Ts'o wrote: > On Sat, Jul 19, 2014 at 01:35:48AM +0200, Hannes Frederic Sowa wrote: > > > + nfrac = ibytes << (ENTROPY_SHIFT + 3); > > > + if (entropy_count < 0) { > > > > Minor nit: maybe also add an unlikely() here? > > Yep, done. > > > > + if

Re: [PATCH] random: check for increase of entropy_count because of signed conversion

2014-07-19 Thread Hannes Frederic Sowa
On Sa, 2014-07-19 at 01:42 -0400, Theodore Ts'o wrote: On Sat, Jul 19, 2014 at 01:35:48AM +0200, Hannes Frederic Sowa wrote: + nfrac = ibytes (ENTROPY_SHIFT + 3); + if (entropy_count 0) { Minor nit: maybe also add an unlikely() here? Yep, done. + if ((unsigned) entropy_count

Re: [PATCH] random: check for increase of entropy_count because of signed conversion

2014-07-18 Thread Theodore Ts'o
On Sat, Jul 19, 2014 at 01:35:48AM +0200, Hannes Frederic Sowa wrote: > > + nfrac = ibytes << (ENTROPY_SHIFT + 3); > > + if (entropy_count < 0) { > > Minor nit: maybe also add an unlikely() here? Yep, done. > > + if ((unsigned) entropy_count > nfrac) > > (unsigned) -> (size_t) > > size_t

Re: [PATCH] random: check for increase of entropy_count because of signed conversion

2014-07-18 Thread Hannes Frederic Sowa
Hi, On Fr, 2014-07-18 at 18:07 -0400, Theodore Ts'o wrote: > From: Hannes Frederic Sowa > > The expression entropy_count -= ibytes << (ENTROPY_SHIFT + 3) could > actually increase entropy_count if during assignment of the unsigned > expression on the RHS (mind the -=) we reduce the value modulo

Re: [PATCH] random: check for increase of entropy_count because of signed conversion

2014-07-18 Thread Theodore Ts'o
On Fri, Jul 18, 2014 at 05:25:04PM -0400, Theodore Ts'o wrote: > > As indicated by credit_entropy_bits entropy_count cannot get negative, > > so I don't see any reason to include a check for entropy_count < 0 > > here. Do you agree? > > No, the check is important; after we subtract ibytes <<

Re: [PATCH] random: check for increase of entropy_count because of signed conversion

2014-07-18 Thread Hannes Frederic Sowa
Hi, On Fri, Jul 18, 2014, at 23:25, Theodore Ts'o wrote: > On Wed, Jul 16, 2014 at 09:18:15PM +0200, Hannes Frederic Sowa wrote: > > The expression entropy_count -= ibytes << (ENTROPY_SHIFT + 3) could > > actually increase entropy_count if during assignment of the unsigned > > expression on the

Re: [PATCH] random: check for increase of entropy_count because of signed conversion

2014-07-18 Thread Theodore Ts'o
On Wed, Jul 16, 2014 at 09:18:15PM +0200, Hannes Frederic Sowa wrote: > The expression entropy_count -= ibytes << (ENTROPY_SHIFT + 3) could > actually increase entropy_count if during assignment of the unsigned > expression on the RHS (mind the -=) we reduce the value modulo > 2^width(int) and

Re: [PATCH] random: check for increase of entropy_count because of signed conversion

2014-07-18 Thread Theodore Ts'o
On Wed, Jul 16, 2014 at 09:18:15PM +0200, Hannes Frederic Sowa wrote: The expression entropy_count -= ibytes (ENTROPY_SHIFT + 3) could actually increase entropy_count if during assignment of the unsigned expression on the RHS (mind the -=) we reduce the value modulo 2^width(int) and assign it

Re: [PATCH] random: check for increase of entropy_count because of signed conversion

2014-07-18 Thread Hannes Frederic Sowa
Hi, On Fri, Jul 18, 2014, at 23:25, Theodore Ts'o wrote: On Wed, Jul 16, 2014 at 09:18:15PM +0200, Hannes Frederic Sowa wrote: The expression entropy_count -= ibytes (ENTROPY_SHIFT + 3) could actually increase entropy_count if during assignment of the unsigned expression on the RHS (mind

Re: [PATCH] random: check for increase of entropy_count because of signed conversion

2014-07-18 Thread Theodore Ts'o
On Fri, Jul 18, 2014 at 05:25:04PM -0400, Theodore Ts'o wrote: As indicated by credit_entropy_bits entropy_count cannot get negative, so I don't see any reason to include a check for entropy_count 0 here. Do you agree? No, the check is important; after we subtract ibytes (ENTROPY_SHIFT

Re: [PATCH] random: check for increase of entropy_count because of signed conversion

2014-07-18 Thread Hannes Frederic Sowa
Hi, On Fr, 2014-07-18 at 18:07 -0400, Theodore Ts'o wrote: From: Hannes Frederic Sowa han...@stressinduktion.org The expression entropy_count -= ibytes (ENTROPY_SHIFT + 3) could actually increase entropy_count if during assignment of the unsigned expression on the RHS (mind the -=) we

Re: [PATCH] random: check for increase of entropy_count because of signed conversion

2014-07-18 Thread Theodore Ts'o
On Sat, Jul 19, 2014 at 01:35:48AM +0200, Hannes Frederic Sowa wrote: + nfrac = ibytes (ENTROPY_SHIFT + 3); + if (entropy_count 0) { Minor nit: maybe also add an unlikely() here? Yep, done. + if ((unsigned) entropy_count nfrac) (unsigned) - (size_t) size_t could also be