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]
Message-ID: <201612100950.bdkh8hGZ%fengguang.wu@intel.com>
Date:   Sat, 10 Dec 2016 09:27:21 +0800
From:   kbuild test robot <lkp@...el.com>
To:     Corentin Labbe <clabbe.montjoie@...il.com>
Cc:     kbuild-all@...org, mpm@...enic.com, herbert@...dor.apana.org.au,
        arnd@...db.de, gregkh@...uxfoundation.org,
        linux-crypto@...r.kernel.org, linux-kernel@...r.kernel.org,
        Corentin Labbe <clabbe.montjoie@...il.com>
Subject: Re: [PATCH 7/7] hwrng: core: Remove two unused include

Hi Corentin,

[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on v4.9-rc8 next-20161209]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Corentin-Labbe/hwrng-core-do-not-use-multiple-blank-lines/20161210-072632
config: i386-randconfig-x007-201649 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All error/warnings (new ones prefixed by >>):

   In file included from include/linux/linkage.h:4:0,
                    from include/linux/kernel.h:6,
                    from include/linux/delay.h:10,
                    from drivers/char/hw_random/core.c:13:
   drivers/char/hw_random/core.c: In function 'rng_dev_open':
>> drivers/char/hw_random/core.c:169:11: error: dereferencing pointer to incomplete type 'struct file'
     if ((filp->f_mode & FMODE_READ) == 0)
              ^
   include/linux/compiler.h:149:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^~~~
>> drivers/char/hw_random/core.c:169:2: note: in expansion of macro 'if'
     if ((filp->f_mode & FMODE_READ) == 0)
     ^~
>> drivers/char/hw_random/core.c:169:22: error: 'FMODE_READ' undeclared (first use in this function)
     if ((filp->f_mode & FMODE_READ) == 0)
                         ^
   include/linux/compiler.h:149:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^~~~
>> drivers/char/hw_random/core.c:169:2: note: in expansion of macro 'if'
     if ((filp->f_mode & FMODE_READ) == 0)
     ^~
   drivers/char/hw_random/core.c:169:22: note: each undeclared identifier is reported only once for each function it appears in
     if ((filp->f_mode & FMODE_READ) == 0)
                         ^
   include/linux/compiler.h:149:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^~~~
>> drivers/char/hw_random/core.c:169:2: note: in expansion of macro 'if'
     if ((filp->f_mode & FMODE_READ) == 0)
     ^~
>> drivers/char/hw_random/core.c:171:21: error: 'FMODE_WRITE' undeclared (first use in this function)
     if (filp->f_mode & FMODE_WRITE)
                        ^
   include/linux/compiler.h:149:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^~~~
   drivers/char/hw_random/core.c:171:2: note: in expansion of macro 'if'
     if (filp->f_mode & FMODE_WRITE)
     ^~
   drivers/char/hw_random/core.c: In function 'rng_dev_read':
>> drivers/char/hw_random/core.c:221:23: error: 'O_NONBLOCK' undeclared (first use in this function)
        !(filp->f_flags & O_NONBLOCK));
                          ^~~~~~~~~~
   drivers/char/hw_random/core.c: At top level:
>> drivers/char/hw_random/core.c:272:21: error: variable 'rng_chrdev_ops' has initializer but incomplete type
    static const struct file_operations rng_chrdev_ops = {
                        ^~~~~~~~~~~~~~~
>> drivers/char/hw_random/core.c:273:2: error: unknown field 'owner' specified in initializer
     .owner  = THIS_MODULE,
     ^
   In file included from include/linux/linkage.h:6:0,
                    from include/linux/kernel.h:6,
                    from include/linux/delay.h:10,
                    from drivers/char/hw_random/core.c:13:
   include/linux/export.h:37:21: warning: excess elements in struct initializer
    #define THIS_MODULE ((struct module *)0)
                        ^
>> drivers/char/hw_random/core.c:273:12: note: in expansion of macro 'THIS_MODULE'
     .owner  = THIS_MODULE,
               ^~~~~~~~~~~
   include/linux/export.h:37:21: note: (near initialization for 'rng_chrdev_ops')
    #define THIS_MODULE ((struct module *)0)
                        ^
>> drivers/char/hw_random/core.c:273:12: note: in expansion of macro 'THIS_MODULE'
     .owner  = THIS_MODULE,
               ^~~~~~~~~~~
>> drivers/char/hw_random/core.c:274:2: error: unknown field 'open' specified in initializer
     .open  = rng_dev_open,
     ^
>> drivers/char/hw_random/core.c:274:11: warning: excess elements in struct initializer
     .open  = rng_dev_open,
              ^~~~~~~~~~~~
   drivers/char/hw_random/core.c:274:11: note: (near initialization for 'rng_chrdev_ops')
>> drivers/char/hw_random/core.c:275:2: error: unknown field 'read' specified in initializer
     .read  = rng_dev_read,
     ^
   drivers/char/hw_random/core.c:275:11: warning: excess elements in struct initializer
     .read  = rng_dev_read,
              ^~~~~~~~~~~~
   drivers/char/hw_random/core.c:275:11: note: (near initialization for 'rng_chrdev_ops')
>> drivers/char/hw_random/core.c:276:2: error: unknown field 'llseek' specified in initializer
     .llseek  = noop_llseek,
     ^
>> drivers/char/hw_random/core.c:276:13: error: 'noop_llseek' undeclared here (not in a function)
     .llseek  = noop_llseek,
                ^~~~~~~~~~~
   drivers/char/hw_random/core.c:276:13: warning: excess elements in struct initializer
   drivers/char/hw_random/core.c:276:13: note: (near initialization for 'rng_chrdev_ops')
>> drivers/char/hw_random/core.c:272:37: error: storage size of 'rng_chrdev_ops' isn't known
    static const struct file_operations rng_chrdev_ops = {
                                        ^~~~~~~~~~~~~~

vim +169 drivers/char/hw_random/core.c

92c7987e7 Corentin Labbe    2016-12-09    7   * Please read Documentation/hw_random.txt for details on use.
92c7987e7 Corentin Labbe    2016-12-09    8   *
92c7987e7 Corentin Labbe    2016-12-09    9   * This software may be used and distributed according to the terms
92c7987e7 Corentin Labbe    2016-12-09   10   * of the GNU General Public License, incorporated herein by reference.
844dd05fe Michael Buesch    2006-06-26   11   */
844dd05fe Michael Buesch    2006-06-26   12  
b70f09c75 Corentin Labbe    2016-12-09  @13  #include <linux/delay.h>
844dd05fe Michael Buesch    2006-06-26   14  #include <linux/device.h>
b70f09c75 Corentin Labbe    2016-12-09   15  #include <linux/err.h>
844dd05fe Michael Buesch    2006-06-26   16  #include <linux/hw_random.h>
844dd05fe Michael Buesch    2006-06-26   17  #include <linux/kernel.h>
be4000bc4 Torsten Duwe      2014-06-14   18  #include <linux/kthread.h>
b70f09c75 Corentin Labbe    2016-12-09   19  #include <linux/miscdevice.h>
b70f09c75 Corentin Labbe    2016-12-09   20  #include <linux/module.h>
d9e797261 Kees Cook         2014-03-03   21  #include <linux/random.h>
b70f09c75 Corentin Labbe    2016-12-09   22  #include <linux/slab.h>
b70f09c75 Corentin Labbe    2016-12-09   23  #include <linux/uaccess.h>
844dd05fe Michael Buesch    2006-06-26   24  
844dd05fe Michael Buesch    2006-06-26   25  #define RNG_MODULE_NAME		"hw_random"
844dd05fe Michael Buesch    2006-06-26   26  
844dd05fe Michael Buesch    2006-06-26   27  static struct hwrng *current_rng;
be4000bc4 Torsten Duwe      2014-06-14   28  static struct task_struct *hwrng_fill;
844dd05fe Michael Buesch    2006-06-26   29  static LIST_HEAD(rng_list);
9372b35e1 Rusty Russell     2014-12-08   30  /* Protects rng_list and current_rng */
844dd05fe Michael Buesch    2006-06-26   31  static DEFINE_MUTEX(rng_mutex);
9372b35e1 Rusty Russell     2014-12-08   32  /* Protects rng read functions, data_avail, rng_buffer and rng_fillbuf */
9372b35e1 Rusty Russell     2014-12-08   33  static DEFINE_MUTEX(reading_mutex);
9996508b3 Ian Molton        2009-12-01   34  static int data_avail;
be4000bc4 Torsten Duwe      2014-06-14   35  static u8 *rng_buffer, *rng_fillbuf;
0f734e6e7 Torsten Duwe      2014-06-14   36  static unsigned short current_quality;
0f734e6e7 Torsten Duwe      2014-06-14   37  static unsigned short default_quality; /* = 0; default to "off" */
be4000bc4 Torsten Duwe      2014-06-14   38  
be4000bc4 Torsten Duwe      2014-06-14   39  module_param(current_quality, ushort, 0644);
be4000bc4 Torsten Duwe      2014-06-14   40  MODULE_PARM_DESC(current_quality,
be4000bc4 Torsten Duwe      2014-06-14   41  		 "current hwrng entropy estimation per mill");
0f734e6e7 Torsten Duwe      2014-06-14   42  module_param(default_quality, ushort, 0644);
0f734e6e7 Torsten Duwe      2014-06-14   43  MODULE_PARM_DESC(default_quality,
0f734e6e7 Torsten Duwe      2014-06-14   44  		 "default entropy content of hwrng per mill");
be4000bc4 Torsten Duwe      2014-06-14   45  
ff77c150f Herbert Xu        2014-12-23   46  static void drop_current_rng(void);
90ac41bd4 Herbert Xu        2014-12-23   47  static int hwrng_init(struct hwrng *rng);
be4000bc4 Torsten Duwe      2014-06-14   48  static void start_khwrngd(void);
f7f154f12 Rusty Russell     2013-03-05   49  
d3cc79964 Amit Shah         2014-07-10   50  static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size,
d3cc79964 Amit Shah         2014-07-10   51  			       int wait);
d3cc79964 Amit Shah         2014-07-10   52  
f7f154f12 Rusty Russell     2013-03-05   53  static size_t rng_buffer_size(void)
f7f154f12 Rusty Russell     2013-03-05   54  {
f7f154f12 Rusty Russell     2013-03-05   55  	return SMP_CACHE_BYTES < 32 ? 32 : SMP_CACHE_BYTES;
f7f154f12 Rusty Russell     2013-03-05   56  }
844dd05fe Michael Buesch    2006-06-26   57  
d3cc79964 Amit Shah         2014-07-10   58  static void add_early_randomness(struct hwrng *rng)
d3cc79964 Amit Shah         2014-07-10   59  {
d3cc79964 Amit Shah         2014-07-10   60  	int bytes_read;
6d4952d9d Andrew Lutomirski 2016-10-17   61  	size_t size = min_t(size_t, 16, rng_buffer_size());
d3cc79964 Amit Shah         2014-07-10   62  
9372b35e1 Rusty Russell     2014-12-08   63  	mutex_lock(&reading_mutex);
6d4952d9d Andrew Lutomirski 2016-10-17   64  	bytes_read = rng_get_data(rng, rng_buffer, size, 1);
9372b35e1 Rusty Russell     2014-12-08   65  	mutex_unlock(&reading_mutex);
d3cc79964 Amit Shah         2014-07-10   66  	if (bytes_read > 0)
6d4952d9d Andrew Lutomirski 2016-10-17   67  		add_device_randomness(rng_buffer, bytes_read);
d3cc79964 Amit Shah         2014-07-10   68  }
d3cc79964 Amit Shah         2014-07-10   69  
3a2c0ba5a Rusty Russell     2014-12-08   70  static inline void cleanup_rng(struct kref *kref)
3a2c0ba5a Rusty Russell     2014-12-08   71  {
3a2c0ba5a Rusty Russell     2014-12-08   72  	struct hwrng *rng = container_of(kref, struct hwrng, ref);
3a2c0ba5a Rusty Russell     2014-12-08   73  
3a2c0ba5a Rusty Russell     2014-12-08   74  	if (rng->cleanup)
3a2c0ba5a Rusty Russell     2014-12-08   75  		rng->cleanup(rng);
a027f30d7 Rusty Russell     2014-12-08   76  
77584ee57 Herbert Xu        2014-12-23   77  	complete(&rng->cleanup_done);
3a2c0ba5a Rusty Russell     2014-12-08   78  }
3a2c0ba5a Rusty Russell     2014-12-08   79  
90ac41bd4 Herbert Xu        2014-12-23   80  static int set_current_rng(struct hwrng *rng)
3a2c0ba5a Rusty Russell     2014-12-08   81  {
90ac41bd4 Herbert Xu        2014-12-23   82  	int err;
90ac41bd4 Herbert Xu        2014-12-23   83  
3a2c0ba5a Rusty Russell     2014-12-08   84  	BUG_ON(!mutex_is_locked(&rng_mutex));
90ac41bd4 Herbert Xu        2014-12-23   85  
90ac41bd4 Herbert Xu        2014-12-23   86  	err = hwrng_init(rng);
90ac41bd4 Herbert Xu        2014-12-23   87  	if (err)
90ac41bd4 Herbert Xu        2014-12-23   88  		return err;
90ac41bd4 Herbert Xu        2014-12-23   89  
ff77c150f Herbert Xu        2014-12-23   90  	drop_current_rng();
3a2c0ba5a Rusty Russell     2014-12-08   91  	current_rng = rng;
90ac41bd4 Herbert Xu        2014-12-23   92  
90ac41bd4 Herbert Xu        2014-12-23   93  	return 0;
3a2c0ba5a Rusty Russell     2014-12-08   94  }
3a2c0ba5a Rusty Russell     2014-12-08   95  
3a2c0ba5a Rusty Russell     2014-12-08   96  static void drop_current_rng(void)
3a2c0ba5a Rusty Russell     2014-12-08   97  {
3a2c0ba5a Rusty Russell     2014-12-08   98  	BUG_ON(!mutex_is_locked(&rng_mutex));
3a2c0ba5a Rusty Russell     2014-12-08   99  	if (!current_rng)
3a2c0ba5a Rusty Russell     2014-12-08  100  		return;
3a2c0ba5a Rusty Russell     2014-12-08  101  
3a2c0ba5a Rusty Russell     2014-12-08  102  	/* decrease last reference for triggering the cleanup */
3a2c0ba5a Rusty Russell     2014-12-08  103  	kref_put(&current_rng->ref, cleanup_rng);
3a2c0ba5a Rusty Russell     2014-12-08  104  	current_rng = NULL;
3a2c0ba5a Rusty Russell     2014-12-08  105  }
3a2c0ba5a Rusty Russell     2014-12-08  106  
3a2c0ba5a Rusty Russell     2014-12-08  107  /* Returns ERR_PTR(), NULL or refcounted hwrng */
3a2c0ba5a Rusty Russell     2014-12-08  108  static struct hwrng *get_current_rng(void)
3a2c0ba5a Rusty Russell     2014-12-08  109  {
3a2c0ba5a Rusty Russell     2014-12-08  110  	struct hwrng *rng;
3a2c0ba5a Rusty Russell     2014-12-08  111  
3a2c0ba5a Rusty Russell     2014-12-08  112  	if (mutex_lock_interruptible(&rng_mutex))
3a2c0ba5a Rusty Russell     2014-12-08  113  		return ERR_PTR(-ERESTARTSYS);
3a2c0ba5a Rusty Russell     2014-12-08  114  
3a2c0ba5a Rusty Russell     2014-12-08  115  	rng = current_rng;
3a2c0ba5a Rusty Russell     2014-12-08  116  	if (rng)
3a2c0ba5a Rusty Russell     2014-12-08  117  		kref_get(&rng->ref);
3a2c0ba5a Rusty Russell     2014-12-08  118  
3a2c0ba5a Rusty Russell     2014-12-08  119  	mutex_unlock(&rng_mutex);
3a2c0ba5a Rusty Russell     2014-12-08  120  	return rng;
3a2c0ba5a Rusty Russell     2014-12-08  121  }
3a2c0ba5a Rusty Russell     2014-12-08  122  
3a2c0ba5a Rusty Russell     2014-12-08  123  static void put_rng(struct hwrng *rng)
3a2c0ba5a Rusty Russell     2014-12-08  124  {
3a2c0ba5a Rusty Russell     2014-12-08  125  	/*
3a2c0ba5a Rusty Russell     2014-12-08  126  	 * Hold rng_mutex here so we serialize in case they set_current_rng
3a2c0ba5a Rusty Russell     2014-12-08  127  	 * on rng again immediately.
3a2c0ba5a Rusty Russell     2014-12-08  128  	 */
3a2c0ba5a Rusty Russell     2014-12-08  129  	mutex_lock(&rng_mutex);
3a2c0ba5a Rusty Russell     2014-12-08  130  	if (rng)
3a2c0ba5a Rusty Russell     2014-12-08  131  		kref_put(&rng->ref, cleanup_rng);
3a2c0ba5a Rusty Russell     2014-12-08  132  	mutex_unlock(&rng_mutex);
3a2c0ba5a Rusty Russell     2014-12-08  133  }
3a2c0ba5a Rusty Russell     2014-12-08  134  
90ac41bd4 Herbert Xu        2014-12-23  135  static int hwrng_init(struct hwrng *rng)
844dd05fe Michael Buesch    2006-06-26  136  {
15b66cd54 Herbert Xu        2014-12-23  137  	if (kref_get_unless_zero(&rng->ref))
15b66cd54 Herbert Xu        2014-12-23  138  		goto skip_init;
15b66cd54 Herbert Xu        2014-12-23  139  
d3cc79964 Amit Shah         2014-07-10  140  	if (rng->init) {
d3cc79964 Amit Shah         2014-07-10  141  		int ret;
d3cc79964 Amit Shah         2014-07-10  142  
d3cc79964 Amit Shah         2014-07-10  143  		ret =  rng->init(rng);
d3cc79964 Amit Shah         2014-07-10  144  		if (ret)
d3cc79964 Amit Shah         2014-07-10  145  			return ret;
d3cc79964 Amit Shah         2014-07-10  146  	}
15b66cd54 Herbert Xu        2014-12-23  147  
15b66cd54 Herbert Xu        2014-12-23  148  	kref_init(&rng->ref);
15b66cd54 Herbert Xu        2014-12-23  149  	reinit_completion(&rng->cleanup_done);
15b66cd54 Herbert Xu        2014-12-23  150  
15b66cd54 Herbert Xu        2014-12-23  151  skip_init:
d3cc79964 Amit Shah         2014-07-10  152  	add_early_randomness(rng);
be4000bc4 Torsten Duwe      2014-06-14  153  
0f734e6e7 Torsten Duwe      2014-06-14  154  	current_quality = rng->quality ? : default_quality;
506bf0c04 Keith Packard     2015-03-18  155  	if (current_quality > 1024)
506bf0c04 Keith Packard     2015-03-18  156  		current_quality = 1024;
0f734e6e7 Torsten Duwe      2014-06-14  157  
0f734e6e7 Torsten Duwe      2014-06-14  158  	if (current_quality == 0 && hwrng_fill)
0f734e6e7 Torsten Duwe      2014-06-14  159  		kthread_stop(hwrng_fill);
be4000bc4 Torsten Duwe      2014-06-14  160  	if (current_quality > 0 && !hwrng_fill)
be4000bc4 Torsten Duwe      2014-06-14  161  		start_khwrngd();
be4000bc4 Torsten Duwe      2014-06-14  162  
844dd05fe Michael Buesch    2006-06-26  163  	return 0;
844dd05fe Michael Buesch    2006-06-26  164  }
844dd05fe Michael Buesch    2006-06-26  165  
844dd05fe Michael Buesch    2006-06-26  166  static int rng_dev_open(struct inode *inode, struct file *filp)
844dd05fe Michael Buesch    2006-06-26  167  {
844dd05fe Michael Buesch    2006-06-26  168  	/* enforce read-only access to this chrdev */
844dd05fe Michael Buesch    2006-06-26 @169  	if ((filp->f_mode & FMODE_READ) == 0)
844dd05fe Michael Buesch    2006-06-26  170  		return -EINVAL;
844dd05fe Michael Buesch    2006-06-26 @171  	if (filp->f_mode & FMODE_WRITE)
844dd05fe Michael Buesch    2006-06-26  172  		return -EINVAL;
844dd05fe Michael Buesch    2006-06-26  173  	return 0;
844dd05fe Michael Buesch    2006-06-26  174  }
844dd05fe Michael Buesch    2006-06-26  175  
9996508b3 Ian Molton        2009-12-01  176  static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size,
9996508b3 Ian Molton        2009-12-01  177  			int wait) {
9996508b3 Ian Molton        2009-12-01  178  	int present;
9996508b3 Ian Molton        2009-12-01  179  
9372b35e1 Rusty Russell     2014-12-08  180  	BUG_ON(!mutex_is_locked(&reading_mutex));
9996508b3 Ian Molton        2009-12-01  181  	if (rng->read)
9996508b3 Ian Molton        2009-12-01  182  		return rng->read(rng, (void *)buffer, size, wait);
9996508b3 Ian Molton        2009-12-01  183  
9996508b3 Ian Molton        2009-12-01  184  	if (rng->data_present)
9996508b3 Ian Molton        2009-12-01  185  		present = rng->data_present(rng, wait);
9996508b3 Ian Molton        2009-12-01  186  	else
9996508b3 Ian Molton        2009-12-01  187  		present = 1;
9996508b3 Ian Molton        2009-12-01  188  
9996508b3 Ian Molton        2009-12-01  189  	if (present)
9996508b3 Ian Molton        2009-12-01  190  		return rng->data_read(rng, (u32 *)buffer);
9996508b3 Ian Molton        2009-12-01  191  
9996508b3 Ian Molton        2009-12-01  192  	return 0;
9996508b3 Ian Molton        2009-12-01  193  }
9996508b3 Ian Molton        2009-12-01  194  
844dd05fe Michael Buesch    2006-06-26  195  static ssize_t rng_dev_read(struct file *filp, char __user *buf,
844dd05fe Michael Buesch    2006-06-26  196  			    size_t size, loff_t *offp)
844dd05fe Michael Buesch    2006-06-26  197  {
844dd05fe Michael Buesch    2006-06-26  198  	ssize_t ret = 0;
984e976f5 Patrick McHardy   2007-11-21  199  	int err = 0;
9996508b3 Ian Molton        2009-12-01  200  	int bytes_read, len;
3a2c0ba5a Rusty Russell     2014-12-08  201  	struct hwrng *rng;
844dd05fe Michael Buesch    2006-06-26  202  
844dd05fe Michael Buesch    2006-06-26  203  	while (size) {
3a2c0ba5a Rusty Russell     2014-12-08  204  		rng = get_current_rng();
3a2c0ba5a Rusty Russell     2014-12-08  205  		if (IS_ERR(rng)) {
3a2c0ba5a Rusty Russell     2014-12-08  206  			err = PTR_ERR(rng);
844dd05fe Michael Buesch    2006-06-26  207  			goto out;
9996508b3 Ian Molton        2009-12-01  208  		}
3a2c0ba5a Rusty Russell     2014-12-08  209  		if (!rng) {
844dd05fe Michael Buesch    2006-06-26  210  			err = -ENODEV;
3a2c0ba5a Rusty Russell     2014-12-08  211  			goto out;
844dd05fe Michael Buesch    2006-06-26  212  		}
984e976f5 Patrick McHardy   2007-11-21  213  
1ab87298c Jiri Slaby        2015-11-27  214  		if (mutex_lock_interruptible(&reading_mutex)) {
1ab87298c Jiri Slaby        2015-11-27  215  			err = -ERESTARTSYS;
1ab87298c Jiri Slaby        2015-11-27  216  			goto out_put;
1ab87298c Jiri Slaby        2015-11-27  217  		}
9996508b3 Ian Molton        2009-12-01  218  		if (!data_avail) {
3a2c0ba5a Rusty Russell     2014-12-08  219  			bytes_read = rng_get_data(rng, rng_buffer,
f7f154f12 Rusty Russell     2013-03-05  220  				rng_buffer_size(),
9996508b3 Ian Molton        2009-12-01 @221  				!(filp->f_flags & O_NONBLOCK));
893f11286 Ralph Wuerthner   2008-04-17  222  			if (bytes_read < 0) {
893f11286 Ralph Wuerthner   2008-04-17  223  				err = bytes_read;
9372b35e1 Rusty Russell     2014-12-08  224  				goto out_unlock_reading;
9996508b3 Ian Molton        2009-12-01  225  			}
9996508b3 Ian Molton        2009-12-01  226  			data_avail = bytes_read;
893f11286 Ralph Wuerthner   2008-04-17  227  		}
844dd05fe Michael Buesch    2006-06-26  228  
9996508b3 Ian Molton        2009-12-01  229  		if (!data_avail) {
9996508b3 Ian Molton        2009-12-01  230  			if (filp->f_flags & O_NONBLOCK) {
9996508b3 Ian Molton        2009-12-01  231  				err = -EAGAIN;
9372b35e1 Rusty Russell     2014-12-08  232  				goto out_unlock_reading;
9996508b3 Ian Molton        2009-12-01  233  			}
9996508b3 Ian Molton        2009-12-01  234  		} else {
9996508b3 Ian Molton        2009-12-01  235  			len = data_avail;
9996508b3 Ian Molton        2009-12-01  236  			if (len > size)
9996508b3 Ian Molton        2009-12-01  237  				len = size;
9996508b3 Ian Molton        2009-12-01  238  
9996508b3 Ian Molton        2009-12-01  239  			data_avail -= len;
9996508b3 Ian Molton        2009-12-01  240  
9996508b3 Ian Molton        2009-12-01  241  			if (copy_to_user(buf + ret, rng_buffer + data_avail,
9996508b3 Ian Molton        2009-12-01  242  								len)) {
844dd05fe Michael Buesch    2006-06-26  243  				err = -EFAULT;
9372b35e1 Rusty Russell     2014-12-08  244  				goto out_unlock_reading;
9996508b3 Ian Molton        2009-12-01  245  			}
9996508b3 Ian Molton        2009-12-01  246  
9996508b3 Ian Molton        2009-12-01  247  			size -= len;
9996508b3 Ian Molton        2009-12-01  248  			ret += len;
844dd05fe Michael Buesch    2006-06-26  249  		}
844dd05fe Michael Buesch    2006-06-26  250  
9372b35e1 Rusty Russell     2014-12-08  251  		mutex_unlock(&reading_mutex);
3a2c0ba5a Rusty Russell     2014-12-08  252  		put_rng(rng);
9996508b3 Ian Molton        2009-12-01  253  
844dd05fe Michael Buesch    2006-06-26  254  		if (need_resched())
844dd05fe Michael Buesch    2006-06-26  255  			schedule_timeout_interruptible(1);
9996508b3 Ian Molton        2009-12-01  256  
9996508b3 Ian Molton        2009-12-01  257  		if (signal_pending(current)) {
844dd05fe Michael Buesch    2006-06-26  258  			err = -ERESTARTSYS;
844dd05fe Michael Buesch    2006-06-26  259  			goto out;
844dd05fe Michael Buesch    2006-06-26  260  		}
9996508b3 Ian Molton        2009-12-01  261  	}
844dd05fe Michael Buesch    2006-06-26  262  out:
844dd05fe Michael Buesch    2006-06-26  263  	return ret ? : err;
3a2c0ba5a Rusty Russell     2014-12-08  264  
9372b35e1 Rusty Russell     2014-12-08  265  out_unlock_reading:
9372b35e1 Rusty Russell     2014-12-08  266  	mutex_unlock(&reading_mutex);
1ab87298c Jiri Slaby        2015-11-27  267  out_put:
3a2c0ba5a Rusty Russell     2014-12-08  268  	put_rng(rng);
3a2c0ba5a Rusty Russell     2014-12-08  269  	goto out;
844dd05fe Michael Buesch    2006-06-26  270  }
844dd05fe Michael Buesch    2006-06-26  271  
62322d255 Arjan van de Ven  2006-07-03 @272  static const struct file_operations rng_chrdev_ops = {
844dd05fe Michael Buesch    2006-06-26 @273  	.owner		= THIS_MODULE,
844dd05fe Michael Buesch    2006-06-26 @274  	.open		= rng_dev_open,
844dd05fe Michael Buesch    2006-06-26 @275  	.read		= rng_dev_read,
6038f373a Arnd Bergmann     2010-08-15 @276  	.llseek		= noop_llseek,
844dd05fe Michael Buesch    2006-06-26  277  };
844dd05fe Michael Buesch    2006-06-26  278  
0daa7a0af Takashi Iwai      2015-02-02  279  static const struct attribute_group *rng_dev_groups[];

:::::: The code at line 169 was first introduced by commit
:::::: 844dd05fec172d98b0dacecd9b9e9f6595204c13 [PATCH] Add new generic HW RNG core

:::::: TO: Michael Buesch <mb@...sch.de>
:::::: CC: Linus Torvalds <torvalds@...osdl.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

Download attachment ".config.gz" of type "application/gzip" (17496 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ