LCOV - code coverage report
Current view: top level - drivers/gpu/drm/lib - drm_random.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 14 14 100.0 %
Date: 2023-07-19 18:55:55 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0
       2             : #include <linux/bitops.h>
       3             : #include <linux/kernel.h>
       4             : #include <linux/random.h>
       5             : #include <linux/slab.h>
       6             : #include <linux/types.h>
       7             : 
       8             : #include "drm_random.h"
       9             : 
      10           4 : u32 drm_prandom_u32_max_state(u32 ep_ro, struct rnd_state *state)
      11             : {
      12     4083725 :         return upper_32_bits((u64)prandom_u32_state(state) * ep_ro);
      13             : }
      14             : EXPORT_SYMBOL(drm_prandom_u32_max_state);
      15             : 
      16         691 : void drm_random_reorder(unsigned int *order, unsigned int count,
      17             :                         struct rnd_state *state)
      18             : {
      19             :         unsigned int i, j;
      20             : 
      21     4084412 :         for (i = 0; i < count; ++i) {
      22             :                 BUILD_BUG_ON(sizeof(unsigned int) > sizeof(u32));
      23     4083721 :                 j = drm_prandom_u32_max_state(count, state);
      24     4083721 :                 swap(order[i], order[j]);
      25             :         }
      26         691 : }
      27             : EXPORT_SYMBOL(drm_random_reorder);
      28             : 
      29         160 : unsigned int *drm_random_order(unsigned int count, struct rnd_state *state)
      30             : {
      31             :         unsigned int *order, i;
      32             : 
      33         160 :         order = kmalloc_array(count, sizeof(*order), GFP_KERNEL);
      34         160 :         if (!order)
      35             :                 return order;
      36             : 
      37      205833 :         for (i = 0; i < count; i++)
      38      205833 :                 order[i] = i;
      39             : 
      40         160 :         drm_random_reorder(order, count, state);
      41         160 :         return order;
      42             : }
      43             : EXPORT_SYMBOL(drm_random_order);

Generated by: LCOV version 1.14