Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp678176ybh; Sun, 12 Jul 2020 20:22:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXqt6D/3sRqtr7pP3lG6mUUYUeR2HBBelKVuqz/iqWum4TjUCnyooqF0RZaq2pV7I0mGwP X-Received: by 2002:a17:907:20b0:: with SMTP id pw16mr17584369ejb.551.1594610543185; Sun, 12 Jul 2020 20:22:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594610543; cv=none; d=google.com; s=arc-20160816; b=VGYMMf50M2M6vBO6wHYvCljZgZpAt5GPxun7sng3DVhzdZEJ7nqJkMAn/tbKTFDAuo 3xwdqSQF1MXev4BEHA8CcW4Nq4b8RxnfTMR0e2u24qeXtlR1R32DMNzRvoQ0ct7lTYwv gn4LhoD8qCBCe5bDSQgvzEaSpQ2G92jefWnRoQRcwDPUV8Q8+Ly1iYdT4EHD9WjoL8K7 e91KJXool+2IIip/0CNpGO29rLwLwX6dkIG46W13iZ6IDFxkT4uWEhbdvsnhdcTm/Zo1 mWDoaP89F7p1dDR12BFQgzpq2KtiCrhsIpjJYpzhb5jdH6N5yQNR5pFKWpuLuQNxyI31 dGsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=FqBhf/wXork2iz5ZmVBFIfxYI4swpxPYsb+Goh/x6l0=; b=H0VZ9V089dk7FoNwprLgWQT+spSncCYYx0MAWKqz0SD3Ig+97itTt+Lhqbb+sUy8bM 1LnP9k00HmsdbsOjMPsqeXGrW5DQOC+qr3CtT0P46Dizl6gaHWaHKs2lg3iz3VxYYYvC xg6U9sTZj8SZlWxpR+5BFNJDHE7y+0FgANUPup/L4R4VpmXWEdCMp9lWY5Oo14Wbqs4L SbjUvDof5551uhK/HWhsmhHi3nCdyflD5oKWZRE6G6bMiQMRvkFk0tyjTzHWVGM6ODHG FZ2DyS1B8jLd9BAictoLDh2Sk3Cimla3w+eJkSonnRpR4LW7eXQaPnUI83DrwnLYrCq7 qw4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h25si9567386edv.231.2020.07.12.20.21.59; Sun, 12 Jul 2020 20:22:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726684AbgGMDVN (ORCPT + 99 others); Sun, 12 Jul 2020 23:21:13 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39815 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726261AbgGMDVM (ORCPT ); Sun, 12 Jul 2020 23:21:12 -0400 Received: by mail-wm1-f65.google.com with SMTP id w3so11640408wmi.4 for ; Sun, 12 Jul 2020 20:21:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FqBhf/wXork2iz5ZmVBFIfxYI4swpxPYsb+Goh/x6l0=; b=SzhzeiZ8LexEMPUmBrTiZkFpY9+vjTGGVO4WEzIS0BrNl2mUGpQTRyqaTzSyMXHnj5 mLqCv95VTcHg7jMKqrkE5ms9K6sYbm7G12HjLkAn/6xCUlaZaR6PYhLUSveY5qUnFHzI vJTJyG1EX+I/psq0Jlky8avdG6XlTvECeW5+DB/39narMiH0BTpIfVOTTodeW1gIyKPf 07x3zwAjPR6fcjV9KDuNb3w0muG9yRGLwQY8Rdh3x8vq8W+dMkyU0WaQgW8zbueq90jo xHNQHFKFzMaoewfj320OsPj2EYBTo7pbXOVEGv4jSF/x1eRY+F/Wi6M/cl9oMErG/1bu 68Rg== X-Gm-Message-State: AOAM531o2tmYaJy+h0E+E9NOlHYnKFzyP3r/bhUjzzR5MX6/m2Cjt43O hmmsjJoN49QTg3IH4lloNSR5dskov9s3+xt3wq4= X-Received: by 2002:a1c:7d56:: with SMTP id y83mr17722620wmc.154.1594610470272; Sun, 12 Jul 2020 20:21:10 -0700 (PDT) MIME-Version: 1.0 References: <4af50c95-36f6-7a61-5a22-2949970fe7a5@linux.intel.com> <93e1c3b1-ee77-a94d-8806-049e0245fab7@linux.intel.com> In-Reply-To: <93e1c3b1-ee77-a94d-8806-049e0245fab7@linux.intel.com> From: Namhyung Kim Date: Mon, 13 Jul 2020 12:20:59 +0900 Message-ID: Subject: Re: [PATCH v10 05/15] perf evlist: implement control command handling functions To: Alexey Budankov Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Andi Kleen , linux-kernel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 8, 2020 at 4:50 PM Alexey Budankov wrote: > > > Implement functions of initialization, finalization and processing > of control command messages coming from control file descriptors. > Allocate control file descriptor as descriptor at struct pollfd > object of evsel_list for atomic poll() operation. > > Signed-off-by: Alexey Budankov > --- [SNIP] > +static int evlist__ctlfd_recv(struct evlist *evlist, enum evlist_ctl_cmd *cmd, > + char *cmd_data, size_t data_size) > +{ > + int err; > + char c; > + size_t bytes_read = 0; > + > + memset(cmd_data, 0, data_size--); I overlooked the '--' at the end and thought there might be buffer overflow.. Care to add a comment? > + > + do { > + err = read(evlist->ctl_fd.fd, &c, 1); Maybe I missed earlier discussion, but do we really want this 1 byte read in a loop? Thanks Namhyung > + if (err > 0) { > + if (c == '\n' || c == '\0') > + break; > + cmd_data[bytes_read++] = c; > + if (bytes_read == data_size) > + break; > + } else { > + if (err == -1) > + pr_err("Failed to read from ctlfd %d: %m\n", evlist->ctl_fd.fd); > + break; > + } > + } while (1); > + > + pr_debug("Message from ctl_fd: \"%s%s\"\n", cmd_data, > + bytes_read == data_size ? "" : c == '\n' ? "\\n" : "\\0"); > + > + if (err > 0) { > + if (!strncmp(cmd_data, EVLIST_CTL_CMD_ENABLE_TAG, > + (sizeof(EVLIST_CTL_CMD_ENABLE_TAG)-1))) { > + *cmd = EVLIST_CTL_CMD_ENABLE; > + } else if (!strncmp(cmd_data, EVLIST_CTL_CMD_DISABLE_TAG, > + (sizeof(EVLIST_CTL_CMD_DISABLE_TAG)-1))) { > + *cmd = EVLIST_CTL_CMD_DISABLE; > + } > + } > + > + return err; > +}