Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp1845298rwb; Sun, 4 Sep 2022 03:33:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR7aAzOsan+SQ0hkby2wSy+tHeAmfNZ9gl3S91wI0icw9TboG6lNBVi0MiTbOPQxZT4l41uS X-Received: by 2002:a17:907:7215:b0:741:416f:fb59 with SMTP id dr21-20020a170907721500b00741416ffb59mr26868546ejc.150.1662287587417; Sun, 04 Sep 2022 03:33:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662287587; cv=none; d=google.com; s=arc-20160816; b=xLJ11d5n1+0mLJUx++4XUAtvBcgvU7a8iRjNi5XyHPU4mYKLSC/7V1LplEL9dL1jIg dGpride9ZPwpUtkq8RpcaFfAye3zth9jCPlLNYR5C5K+OPHQbAD9VoGJTykRN8dh+0VS jkuQhnDMXZkSpyyJrRS5moFDS4WxL3yvWIeQaMofun7dYZxGMqac/dSj4BvSYfter/el R5WR+LbHhx70vXrWnzps7PmsEuh8i4YE3dAzIcPyJop0S4sRb2+WtP1pHmm9XLIkFoom neqS8zaH+nDgCVrzFCUAY2aDJ2UtNvQ+B2GZcyc2GuCTokWIiiT5rMQq4aBFetDMYQcQ d3uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CzV6PoRgjS7oFZN5XCB/sK03pWW2mk4vqVlRZdNee8s=; b=v9zI+xKEs/jkQN+GRo7V86bOn73z40u+GDuwhelJe+fdm9NAD4H1Li+fxvtYQBAezQ 5MnwtKpgxOg00/tq0J5EMyFMi1k5h4gnujxVkaZq3qFrWpihVblXy5rpYYTRX5yWSqWu 1ECI0Di7WVGcpv1dgGN4uz0lpriNFhUn/kZHqgc1+nr0Y/T47VeuCixgBdm+d1oHNXQI CJ4Dv26DcH+PlxNkO9/C14rYGVCwRfIwZXI3yPfJviNfFtpYMdEpO4AgkuOTB5mKQOOP K1aZac68vks4c4apa/s5d6cAa7dYYyG7Yg5Y7WA5otnzKnhBcQlDRKTU25w6YeAaOZwx ERPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nGGq1DPD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y6-20020a056402358600b00446c0ce86ddsi6424029edc.424.2022.09.04.03.32.37; Sun, 04 Sep 2022 03:33:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nGGq1DPD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233848AbiIDKTO (ORCPT + 99 others); Sun, 4 Sep 2022 06:19:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233841AbiIDKTK (ORCPT ); Sun, 4 Sep 2022 06:19:10 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BB3E459A0 for ; Sun, 4 Sep 2022 03:19:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662286749; x=1693822749; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lnKCUE+vkLKFfiJr2fTl5TOkcnCtgN+0ikZDQvPTbT8=; b=nGGq1DPD/L+FsGE1sBX9CCV3lHXSfmSAIgAJOi9Fz0zSc6PRNJi5ixKu F3sppr/zyfuiGEdU/yqx4hRe/q8ZbKPj+WbivPFkw7ocrc/3CqDTaKzBZ r6Lg4qSNL8A5PR4XS926gtKTEbxPuMYxcQhY4lhI+uH1P247w2+jckBuq nD2H3234cNisO5vt8foDflStUrSbiaE/khmQE9z3KVV+9I8eVOrITPLh/ pzyieODyAz9gnodPhlFQVD3Q6WdSBY0Q2qRNHggzAMVqA93YqL4xlpjaJ hEr8bO5RXh2yNdjJNJHutvh5wE2dN4WtTIWiXsf3s32SLalQ4MJVlQZTj g==; X-IronPort-AV: E=McAfee;i="6500,9779,10459"; a="382529103" X-IronPort-AV: E=Sophos;i="5.93,289,1654585200"; d="scan'208";a="382529103" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Sep 2022 03:19:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,289,1654585200"; d="scan'208";a="646589526" Received: from crojewsk-ctrl.igk.intel.com ([10.102.9.28]) by orsmga001.jf.intel.com with ESMTP; 04 Sep 2022 03:19:05 -0700 From: Cezary Rojewski To: alsa-devel@alsa-project.org, broonie@kernel.org Cc: tiwai@suse.com, perex@perex.cz, amadeuszx.slawinski@linux.intel.com, pierre-louis.bossart@linux.intel.com, hdegoede@redhat.com, lgirdwood@gmail.com, kai.vehmanen@linux.intel.com, peter.ujfalusi@linux.intel.com, ranjani.sridharan@linux.intel.com, yung-chuan.liao@linux.intel.com, willy@infradead.org, linux-kernel@vger.kernel.org, andy@kernel.org, intel-poland@eclists.intel.com, andy.shevchenko@gmail.com, Cezary Rojewski Subject: [PATCH v6 2/2] ASoC: SOF: Remove strsplit_u32() and tokenize_input() Date: Sun, 4 Sep 2022 12:28:40 +0200 Message-Id: <20220904102840.862395-3-cezary.rojewski@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220904102840.862395-1-cezary.rojewski@intel.com> References: <20220904102840.862395-1-cezary.rojewski@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make use of global integer-array parsing helper instead of the internal one as both serve same purpose. With that, both strsplit_u32() and tokenize_input() become unused so remove them. Reviewed-by: Andy Shevchenko Signed-off-by: Cezary Rojewski --- sound/soc/sof/sof-client-probes.c | 104 +++++------------------------- 1 file changed, 15 insertions(+), 89 deletions(-) diff --git a/sound/soc/sof/sof-client-probes.c b/sound/soc/sof/sof-client-probes.c index eb246b823461..ddeabbb5580e 100644 --- a/sound/soc/sof/sof-client-probes.c +++ b/sound/soc/sof/sof-client-probes.c @@ -12,6 +12,8 @@ #include #include #include +#include + #include #include #include "sof-client.h" @@ -410,79 +412,6 @@ static const struct snd_compress_ops sof_probes_compressed_ops = { .copy = sof_probes_compr_copy, }; -/** - * strsplit_u32 - Split string into sequence of u32 tokens - * @buf: String to split into tokens. - * @delim: String containing delimiter characters. - * @tkns: Returned u32 sequence pointer. - * @num_tkns: Returned number of tokens obtained. - */ -static int strsplit_u32(char *buf, const char *delim, u32 **tkns, size_t *num_tkns) -{ - char *s; - u32 *data, *tmp; - size_t count = 0; - size_t cap = 32; - int ret = 0; - - *tkns = NULL; - *num_tkns = 0; - data = kcalloc(cap, sizeof(*data), GFP_KERNEL); - if (!data) - return -ENOMEM; - - while ((s = strsep(&buf, delim)) != NULL) { - ret = kstrtouint(s, 0, data + count); - if (ret) - goto exit; - if (++count >= cap) { - cap *= 2; - tmp = krealloc(data, cap * sizeof(*data), GFP_KERNEL); - if (!tmp) { - ret = -ENOMEM; - goto exit; - } - data = tmp; - } - } - - if (!count) - goto exit; - *tkns = kmemdup(data, count * sizeof(*data), GFP_KERNEL); - if (!(*tkns)) { - ret = -ENOMEM; - goto exit; - } - *num_tkns = count; - -exit: - kfree(data); - return ret; -} - -static int tokenize_input(const char __user *from, size_t count, - loff_t *ppos, u32 **tkns, size_t *num_tkns) -{ - char *buf; - int ret; - - buf = kmalloc(count + 1, GFP_KERNEL); - if (!buf) - return -ENOMEM; - - ret = simple_write_to_buffer(buf, count, ppos, from, count); - if (ret != count) { - ret = ret >= 0 ? -EIO : ret; - goto exit; - } - - buf[count] = '\0'; - ret = strsplit_u32(buf, ",", tkns, num_tkns); -exit: - kfree(buf); - return ret; -} - static ssize_t sof_probes_dfs_points_read(struct file *file, char __user *to, size_t count, loff_t *ppos) { @@ -548,8 +477,8 @@ sof_probes_dfs_points_write(struct file *file, const char __user *from, struct sof_probes_priv *priv = cdev->data; struct device *dev = &cdev->auxdev.dev; struct sof_probe_point_desc *desc; - size_t num_tkns, bytes; - u32 *tkns; + u32 num_elems, *array; + size_t bytes; int ret, err; if (priv->extractor_stream_tag == SOF_PROBES_INVALID_NODE_ID) { @@ -557,16 +486,18 @@ sof_probes_dfs_points_write(struct file *file, const char __user *from, return -ENOENT; } - ret = tokenize_input(from, count, ppos, &tkns, &num_tkns); + ret = parse_int_array_user(from, count, (int **)&array); if (ret < 0) return ret; - bytes = sizeof(*tkns) * num_tkns; - if (!num_tkns || (bytes % sizeof(*desc))) { + + num_elems = *array; + bytes = sizeof(*array) * num_elems; + if (bytes % sizeof(*desc)) { ret = -EINVAL; goto exit; } - desc = (struct sof_probe_point_desc *)tkns; + desc = (struct sof_probe_point_desc *)&array[1]; ret = pm_runtime_resume_and_get(dev); if (ret < 0 && ret != -EACCES) { @@ -583,7 +514,7 @@ sof_probes_dfs_points_write(struct file *file, const char __user *from, if (err < 0) dev_err_ratelimited(dev, "debugfs write failed to idle %d\n", err); exit: - kfree(tkns); + kfree(array); return ret; } @@ -603,22 +534,17 @@ sof_probes_dfs_points_remove_write(struct file *file, const char __user *from, struct sof_client_dev *cdev = file->private_data; struct sof_probes_priv *priv = cdev->data; struct device *dev = &cdev->auxdev.dev; - size_t num_tkns; - u32 *tkns; int ret, err; + u32 *array; if (priv->extractor_stream_tag == SOF_PROBES_INVALID_NODE_ID) { dev_warn(dev, "no extractor stream running\n"); return -ENOENT; } - ret = tokenize_input(from, count, ppos, &tkns, &num_tkns); + ret = parse_int_array_user(from, count, (int **)&array); if (ret < 0) return ret; - if (!num_tkns) { - ret = -EINVAL; - goto exit; - } ret = pm_runtime_resume_and_get(dev); if (ret < 0) { @@ -626,7 +552,7 @@ sof_probes_dfs_points_remove_write(struct file *file, const char __user *from, goto exit; } - ret = sof_probes_points_remove(cdev, tkns, num_tkns); + ret = sof_probes_points_remove(cdev, &array[1], array[0]); if (!ret) ret = count; @@ -635,7 +561,7 @@ sof_probes_dfs_points_remove_write(struct file *file, const char __user *from, if (err < 0) dev_err_ratelimited(dev, "debugfs write failed to idle %d\n", err); exit: - kfree(tkns); + kfree(array); return ret; } -- 2.25.1