All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] lib/string_helpers: Introduce tokenize_user_input()
@ 2022-09-01 17:50 ` Cezary Rojewski
  0 siblings, 0 replies; 17+ messages in thread
From: Cezary Rojewski @ 2022-09-01 17:50 UTC (permalink / raw)
  To: alsa-devel, broonie
  Cc: andy, Cezary Rojewski, kai.vehmanen, yung-chuan.liao, tiwai,
	pierre-louis.bossart, willy, lgirdwood, hdegoede,
	ranjani.sridharan, amadeuszx.slawinski, peter.ujfalusi,
	linux-kernel

Continuation of recent upstream discussion [1] regarding user string
tokenization.

First, tokenize_user_input() is introduced to allow for splitting
specified user string into a sequence of integers. Makes use of
get_options() internally so the parsing logic is not duplicated.

With that done, redundant parts of the sound driver are removed.

Originally similar functionality was added for the SOF sound driver. As
more users are on the horizon, it is desirable to update existing
string_helpers code and provide a unified solution.


Changes in v3:
- relocated tokenize_user_input() implementation to string_helpers as
  requested by Matthew

Changes in v2:
- reused get_options() so no parsing logic is duplicated
- simplified __user variant with help of memdup_user_nul()
  Both suggested by Andy, thanks for thourough review


[1]: https://lore.kernel.org/alsa-devel/20220707091301.1282291-1-cezary.rojewski@intel.com/


Cezary Rojewski (2):
  lib/string_helpers: Introduce tokenize_user_input()
  ASoC: SOF: Remove strsplit_u32() and tokenize_input()

 include/linux/string_helpers.h    |  2 +
 lib/string_helpers.c              | 45 +++++++++++++++
 sound/soc/sof/sof-client-probes.c | 93 ++++---------------------------
 3 files changed, 59 insertions(+), 81 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: [PATCH v3 1/2] lib/string_helpers: Introduce tokenize_user_input()
@ 2022-09-02 20:28 kernel test robot
  0 siblings, 0 replies; 17+ messages in thread
From: kernel test robot @ 2022-09-02 20:28 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 6770 bytes --]

:::::: 
:::::: Manual check reason: "low confidence bisect report"
:::::: Manual check reason: "low confidence static check warning: lib/string_helpers.c:150:20: warning: use of uninitialized value '<unknown>' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]"
:::::: 

BCC: lkp(a)intel.com
CC: kbuild-all(a)lists.01.org
In-Reply-To: <20220901175022.334824-2-cezary.rojewski@intel.com>
References: <20220901175022.334824-2-cezary.rojewski@intel.com>
TO: Cezary Rojewski <cezary.rojewski@intel.com>
TO: alsa-devel(a)alsa-project.org
TO: broonie(a)kernel.org
CC: andy(a)kernel.org
CC: Cezary Rojewski <cezary.rojewski@intel.com>
CC: kai.vehmanen(a)linux.intel.com
CC: yung-chuan.liao(a)linux.intel.com
CC: tiwai(a)suse.com
CC: pierre-louis.bossart(a)linux.intel.com
CC: willy(a)infradead.org
CC: lgirdwood(a)gmail.com
CC: hdegoede(a)redhat.com
CC: Andy Shevchenko <andy.shevchenko@gmail.com>
CC: ranjani.sridharan(a)linux.intel.com
CC: amadeuszx.slawinski(a)linux.intel.com
CC: peter.ujfalusi(a)linux.intel.com
CC: linux-kernel(a)vger.kernel.org

Hi Cezary,

I love your patch! Perhaps something to improve:

[auto build test WARNING on broonie-sound/for-next]
[also build test WARNING on linus/master v6.0-rc3]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Cezary-Rojewski/lib-string_helpers-Introduce-tokenize_user_input/20220902-014254
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
:::::: branch date: 27 hours ago
:::::: commit date: 27 hours ago
config: arm-randconfig-c002-20220901 (https://download.01.org/0day-ci/archive/20220903/202209030411.0HeReNTd-lkp(a)intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/53e2025c60da991b4e879aaf336a6635c0b87b07
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Cezary-Rojewski/lib-string_helpers-Introduce-tokenize_user_input/20220902-014254
        git checkout 53e2025c60da991b4e879aaf336a6635c0b87b07
        # save the config file
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross ARCH=arm KBUILD_USERCFLAGS='-fanalyzer -Wno-error' 

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

gcc_analyzer warnings: (new ones prefixed by >>)
   lib/string_helpers.c: In function 'tokenize_user_input':
>> lib/string_helpers.c:150:20: warning: use of uninitialized value '<unknown>' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
     150 |         int *ints, nints;
         |                    ^~~~~
     'tokenize_user_input': event 1
       |
       |  150 |         int *ints, nints;
       |      |                    ^~~~~
       |      |                    |
       |      |                    (1) use of uninitialized value '<unknown>' here
       |

vim +150 lib/string_helpers.c

16c7fa05829e8b9 Andy Shevchenko 2013-04-30  133  
53e2025c60da991 Cezary Rojewski 2022-09-01  134  /**
53e2025c60da991 Cezary Rojewski 2022-09-01  135   * tokenize_user_input - Split string into a sequence of integers
53e2025c60da991 Cezary Rojewski 2022-09-01  136   * @from:	The user space buffer to read from
53e2025c60da991 Cezary Rojewski 2022-09-01  137   * @ppos:	The current position in the buffer
53e2025c60da991 Cezary Rojewski 2022-09-01  138   * @count:	The maximum number of bytes to read
53e2025c60da991 Cezary Rojewski 2022-09-01  139   * @tkns:	Returned pointer to sequence of integers
53e2025c60da991 Cezary Rojewski 2022-09-01  140   *
53e2025c60da991 Cezary Rojewski 2022-09-01  141   * On success @tkns is allocated and initialized with a sequence of
53e2025c60da991 Cezary Rojewski 2022-09-01  142   * integers extracted from the @from plus an additional element that
53e2025c60da991 Cezary Rojewski 2022-09-01  143   * begins the sequence and specifies the integers count.
53e2025c60da991 Cezary Rojewski 2022-09-01  144   *
53e2025c60da991 Cezary Rojewski 2022-09-01  145   * Caller takes responsibility for freeing @tkns when it is no longer
53e2025c60da991 Cezary Rojewski 2022-09-01  146   * needed.
53e2025c60da991 Cezary Rojewski 2022-09-01  147   */
53e2025c60da991 Cezary Rojewski 2022-09-01  148  int tokenize_user_input(const char __user *from, size_t count, int **tkns)
53e2025c60da991 Cezary Rojewski 2022-09-01  149  {
53e2025c60da991 Cezary Rojewski 2022-09-01 @150  	int *ints, nints;
53e2025c60da991 Cezary Rojewski 2022-09-01  151  	char *buf;
53e2025c60da991 Cezary Rojewski 2022-09-01  152  	int ret = 0;
53e2025c60da991 Cezary Rojewski 2022-09-01  153  
53e2025c60da991 Cezary Rojewski 2022-09-01  154  	buf = memdup_user_nul(from, count);
53e2025c60da991 Cezary Rojewski 2022-09-01  155  	if (IS_ERR(buf))
53e2025c60da991 Cezary Rojewski 2022-09-01  156  		return PTR_ERR(buf);
53e2025c60da991 Cezary Rojewski 2022-09-01  157  
53e2025c60da991 Cezary Rojewski 2022-09-01  158  	get_options(buf, 0, &nints);
53e2025c60da991 Cezary Rojewski 2022-09-01  159  	if (!nints) {
53e2025c60da991 Cezary Rojewski 2022-09-01  160  		ret = -ENOENT;
53e2025c60da991 Cezary Rojewski 2022-09-01  161  		goto free_buf;
53e2025c60da991 Cezary Rojewski 2022-09-01  162  	}
53e2025c60da991 Cezary Rojewski 2022-09-01  163  
53e2025c60da991 Cezary Rojewski 2022-09-01  164  	ints = kcalloc(nints + 1, sizeof(*ints), GFP_KERNEL);
53e2025c60da991 Cezary Rojewski 2022-09-01  165  	if (!ints) {
53e2025c60da991 Cezary Rojewski 2022-09-01  166  		ret = -ENOMEM;
53e2025c60da991 Cezary Rojewski 2022-09-01  167  		goto free_buf;
53e2025c60da991 Cezary Rojewski 2022-09-01  168  	}
53e2025c60da991 Cezary Rojewski 2022-09-01  169  
53e2025c60da991 Cezary Rojewski 2022-09-01  170  	get_options(buf, nints + 1, ints);
53e2025c60da991 Cezary Rojewski 2022-09-01  171  	*tkns = ints;
53e2025c60da991 Cezary Rojewski 2022-09-01  172  
53e2025c60da991 Cezary Rojewski 2022-09-01  173  free_buf:
53e2025c60da991 Cezary Rojewski 2022-09-01  174  	kfree(buf);
53e2025c60da991 Cezary Rojewski 2022-09-01  175  	return ret;
53e2025c60da991 Cezary Rojewski 2022-09-01  176  }
53e2025c60da991 Cezary Rojewski 2022-09-01  177  EXPORT_SYMBOL(tokenize_user_input);
53e2025c60da991 Cezary Rojewski 2022-09-01  178  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

end of thread, other threads:[~2022-09-02 20:28 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-01 17:50 [PATCH v3 0/2] lib/string_helpers: Introduce tokenize_user_input() Cezary Rojewski
2022-09-01 17:50 ` Cezary Rojewski
2022-09-01 17:50 ` [PATCH v3 1/2] " Cezary Rojewski
2022-09-01 17:50   ` Cezary Rojewski
2022-09-01 19:34   ` Andy Shevchenko
2022-09-01 19:34     ` Andy Shevchenko
2022-09-02  7:46     ` Cezary Rojewski
2022-09-02  7:46       ` Cezary Rojewski
2022-09-02  9:04       ` Andy Shevchenko
2022-09-02  9:04         ` Andy Shevchenko
2022-09-01 17:50 ` [PATCH v3 2/2] ASoC: SOF: Remove strsplit_u32() and tokenize_input() Cezary Rojewski
2022-09-01 17:50   ` Cezary Rojewski
2022-09-01 19:38   ` Andy Shevchenko
2022-09-01 19:38     ` Andy Shevchenko
2022-09-02 11:51     ` Cezary Rojewski
2022-09-02 11:51       ` Cezary Rojewski
2022-09-02 20:28 [PATCH v3 1/2] lib/string_helpers: Introduce tokenize_user_input() kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.