Linux backports project
 help / color / mirror / Atom feed
* [PATCH v3] backports: add support for prandom_bytes
@ 2013-12-03 14:10 Johannes Berg
  2013-12-06 16:15 ` Luis R. Rodriguez
  0 siblings, 1 reply; 4+ messages in thread
From: Johannes Berg @ 2013-12-03 14:10 UTC (permalink / raw)
  To: backports; +Cc: Emmanuel Grumbach

From: Emmanuel Grumbach <emmanuel.grumbach@intel.com>

This was added in 3.8 and not used until now.
Since it it being used by the wireless stack, backport it.

Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 backport/backport-include/linux/random.h |  3 +++
 backport/compat/compat-3.8.c             | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/backport/backport-include/linux/random.h b/backport/backport-include/linux/random.h
index 812ce7f..e915106 100644
--- a/backport/backport-include/linux/random.h
+++ b/backport/backport-include/linux/random.h
@@ -8,6 +8,9 @@
 #define prandom_seed(_seed)		srandom32(_seed)
 #define prandom_u32()			random32()
 #define prandom_u32_state(_state)	prandom32(_state)
+/* backport 6582c665d6b882dad8329e05749fbcf119f1ab88 */
+#define prandom_bytes LINUX_BACKPORT(prandom_bytes)
+void prandom_bytes(void *buf, int bytes);
 #endif
 
 #endif /* __BACKPORT_RANDOM_H */
diff --git a/backport/compat/compat-3.8.c b/backport/compat/compat-3.8.c
index d43d386..70d3375 100644
--- a/backport/compat/compat-3.8.c
+++ b/backport/compat/compat-3.8.c
@@ -16,6 +16,7 @@
 #include <linux/module.h>
 #include "hid-ids.h"
 #include <linux/netdevice.h>
+#include <linux/random.h>
 
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,8))
 void netdev_set_default_ethtool_ops(struct net_device *dev,
@@ -419,6 +420,37 @@ int vm_iomap_memory(struct vm_area_struct *vma, phys_addr_t start, unsigned long
 }
 EXPORT_SYMBOL_GPL(vm_iomap_memory);
 
+/**
+ *	prandom_bytes - get the requested number of pseudo-random bytes
+ *	@buf: where to copy the pseudo-random bytes to
+ *	@bytes: the requested number of bytes
+ */
+void prandom_bytes(void *buf, int bytes)
+{
+	unsigned char *p = buf;
+	int i;
+
+	for (i = 0; i < round_down(bytes, sizeof(u32)); i += sizeof(u32)) {
+		u32 random = random32();
+		int j;
+
+		for (j = 0; j < sizeof(u32); j++) {
+			p[i + j] = random;
+			random >>= BITS_PER_BYTE;
+		}
+	}
+
+	if (i < bytes) {
+		u32 random = random32();
+
+		for (; i < bytes; i++) {
+			p[i] = random;
+			random >>= BITS_PER_BYTE;
+		}
+	}
+}
+EXPORT_SYMBOL_GPL(prandom_bytes_state);
+
 #ifdef CONFIG_OF
 /**
  * of_find_property_value_of_size
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] backports: add support for prandom_bytes
  2013-12-03 14:10 [PATCH v3] backports: add support for prandom_bytes Johannes Berg
@ 2013-12-06 16:15 ` Luis R. Rodriguez
  2013-12-06 18:26   ` Luis R. Rodriguez
  0 siblings, 1 reply; 4+ messages in thread
From: Luis R. Rodriguez @ 2013-12-06 16:15 UTC (permalink / raw)
  To: Johannes Berg; +Cc: backports, Emmanuel Grumbach

On Tue, Dec 03, 2013 at 03:10:52PM +0100, Johannes Berg wrote:
> From: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
> 
> This was added in 3.8 and not used until now.
> Since it it being used by the wireless stack, backport it.
> 
> Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
> ---
>  backport/backport-include/linux/random.h |  3 +++
>  backport/compat/compat-3.8.c             | 32 ++++++++++++++++++++++++++++++++
>  2 files changed, 35 insertions(+)
> 
> diff --git a/backport/backport-include/linux/random.h b/backport/backport-include/linux/random.h
> index 812ce7f..e915106 100644
> --- a/backport/backport-include/linux/random.h
> +++ b/backport/backport-include/linux/random.h
> @@ -8,6 +8,9 @@
>  #define prandom_seed(_seed)		srandom32(_seed)
>  #define prandom_u32()			random32()
>  #define prandom_u32_state(_state)	prandom32(_state)
> +/* backport 6582c665d6b882dad8329e05749fbcf119f1ab88 */
> +#define prandom_bytes LINUX_BACKPORT(prandom_bytes)
> +void prandom_bytes(void *buf, int bytes);
>  #endif
>  
>  #endif /* __BACKPORT_RANDOM_H */
> diff --git a/backport/compat/compat-3.8.c b/backport/compat/compat-3.8.c
> index d43d386..70d3375 100644
> --- a/backport/compat/compat-3.8.c
> +++ b/backport/compat/compat-3.8.c
> @@ -16,6 +16,7 @@
>  #include <linux/module.h>
>  #include "hid-ids.h"
>  #include <linux/netdevice.h>
> +#include <linux/random.h>
>  
>  #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,8))
>  void netdev_set_default_ethtool_ops(struct net_device *dev,
> @@ -419,6 +420,37 @@ int vm_iomap_memory(struct vm_area_struct *vma, phys_addr_t start, unsigned long
>  }
>  EXPORT_SYMBOL_GPL(vm_iomap_memory);
>  
> +/**
> + *	prandom_bytes - get the requested number of pseudo-random bytes
> + *	@buf: where to copy the pseudo-random bytes to
> + *	@bytes: the requested number of bytes
> + */
> +void prandom_bytes(void *buf, int bytes)
> +{
> +	unsigned char *p = buf;
> +	int i;
> +
> +	for (i = 0; i < round_down(bytes, sizeof(u32)); i += sizeof(u32)) {
> +		u32 random = random32();
> +		int j;
> +
> +		for (j = 0; j < sizeof(u32); j++) {
> +			p[i + j] = random;
> +			random >>= BITS_PER_BYTE;
> +		}
> +	}
> +
> +	if (i < bytes) {
> +		u32 random = random32();
> +
> +		for (; i < bytes; i++) {
> +			p[i] = random;
> +			random >>= BITS_PER_BYTE;
> +		}
> +	}
> +}
> +EXPORT_SYMBOL_GPL(prandom_bytes_state);

Where is prandom_bytes_state defined? Did you mean prandom_bytes ?
This breaks compilation right now.

  Luis

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] backports: add support for prandom_bytes
  2013-12-06 16:15 ` Luis R. Rodriguez
@ 2013-12-06 18:26   ` Luis R. Rodriguez
  2013-12-08  7:28     ` Grumbach, Emmanuel
  0 siblings, 1 reply; 4+ messages in thread
From: Luis R. Rodriguez @ 2013-12-06 18:26 UTC (permalink / raw)
  To: Johannes Berg; +Cc: backports, Emmanuel Grumbach

On Fri, Dec 06, 2013 at 05:15:31PM +0100, Luis R. Rodriguez wrote:
> On Tue, Dec 03, 2013 at 03:10:52PM +0100, Johannes Berg wrote:
> > +EXPORT_SYMBOL_GPL(prandom_bytes_state);
> 
> Where is prandom_bytes_state defined? Did you mean prandom_bytes ?
> This breaks compilation right now.

I'll fix this upon merge, modifying this without _state fixed things.

  Luis

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH v3] backports: add support for prandom_bytes
  2013-12-06 18:26   ` Luis R. Rodriguez
@ 2013-12-08  7:28     ` Grumbach, Emmanuel
  0 siblings, 0 replies; 4+ messages in thread
From: Grumbach, Emmanuel @ 2013-12-08  7:28 UTC (permalink / raw)
  To: Luis R. Rodriguez, Johannes Berg; +Cc: backports@vger.kernel.org

> From: Luis R. Rodriguez [mailto:mcgrof@gmail.com] On Behalf Of Luis R.
> Rodriguez
> Sent: Friday, December 06, 2013 8:26 PM
> To: Johannes Berg
> Cc: backports@vger.kernel.org; Grumbach, Emmanuel
> Subject: Re: [PATCH v3] backports: add support for prandom_bytes
> 
> On Fri, Dec 06, 2013 at 05:15:31PM +0100, Luis R. Rodriguez wrote:
> > On Tue, Dec 03, 2013 at 03:10:52PM +0100, Johannes Berg wrote:
> > > +EXPORT_SYMBOL_GPL(prandom_bytes_state);
> >
> > Where is prandom_bytes_state defined? Did you mean prandom_bytes ?
> > This breaks compilation right now.
> 
> I'll fix this upon merge, modifying this without _state fixed things.
>

Well... the patch was suggested by Johannes, of course I fixed it before I applied it in our internal tree, and apparently, I should have told him that I had to fix it before asking him to send upstream...
Thanks Luis.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-12-08  7:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-03 14:10 [PATCH v3] backports: add support for prandom_bytes Johannes Berg
2013-12-06 16:15 ` Luis R. Rodriguez
2013-12-06 18:26   ` Luis R. Rodriguez
2013-12-08  7:28     ` Grumbach, Emmanuel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox