linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>
Cc: kbuild-all@lists.01.org, Ingo Molnar <mingo@kernel.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Jiri Olsa <jolsa@redhat.com>, Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Stephane Eranian <eranian@google.com>,
	Andi Kleen <ak@linux.intel.com>, Ian Rogers <irogers@google.com>
Subject: [PATCH] perf/core: fix memdup_user.cocci warnings
Date: Wed, 14 Apr 2021 13:15:33 +0800	[thread overview]
Message-ID: <20210414051533.GA94059@4510e896ae82> (raw)
In-Reply-To: <20210413044133.617921-2-namhyung@kernel.org>

From: kernel test robot <lkp@intel.com>

kernel/events/core.c:5925:13-20: WARNING opportunity for memdup_user

 Use memdup_user rather than duplicating its implementation
 This is a little bit restricted to reduce false positives

Generated by: scripts/coccinelle/api/memdup_user.cocci

CC: Namhyung Kim <namhyung@kernel.org>
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: kernel test robot <lkp@intel.com>
---

url:    https://github.com/0day-ci/linux/commits/Namhyung-Kim/perf-core-Sharing-events-with-multiple-cgroups/20210413-124251
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git cface0326a6c2ae5c8f47bd466f07624b3e348a7

 core.c |   12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5922,15 +5922,9 @@ static long _perf_ioctl(struct perf_even
 
 		cgrp_bufsz = nr_cgrps * sizeof(*cgrp_buf);
 
-		cgrp_buf = kmalloc(cgrp_bufsz, GFP_KERNEL);
-		if (cgrp_buf == NULL)
-			return -ENOMEM;
-
-		if (copy_from_user(cgrp_buf, (u64 __user *)(arg + 8),
-				   cgrp_bufsz)) {
-			kfree(cgrp_buf);
-			return -EFAULT;
-		}
+		cgrp_buf = memdup_user((u64 __user *)(arg + 8), cgrp_bufsz);
+		if (IS_ERR(cgrp_buf))
+			return PTR_ERR(cgrp_buf);
 
 		ret = perf_event_attach_cgroup_node(event, nr_cgrps, cgrp_buf);
 

  parent reply	other threads:[~2021-04-14  5:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-13  4:41 [PATCH v2 0/2] perf core: Sharing events with multiple cgroups Namhyung Kim
2021-04-13  4:41 ` [PATCH v2 1/2] perf/core: Share an event " Namhyung Kim
2021-04-13  7:03   ` kernel test robot
2021-04-13  9:39   ` kernel test robot
2021-04-14  5:15   ` kernel test robot
2021-04-14  5:15   ` kernel test robot [this message]
2021-04-13  4:41 ` [PATCH v2 2/2] perf/core: Support reading group events with shared cgroups Namhyung Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210414051533.GA94059@4510e896ae82 \
    --to=lkp@intel.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=jolsa@redhat.com \
    --cc=kbuild-all@lists.01.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).