Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2995863pxb; Tue, 24 Aug 2021 12:28:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzxZpzud/tDPrJKapFtbwtptqmMdCDfcuWypnXcMUJRiXSpVk/kD6c5onJtLZSRlmKJM1J X-Received: by 2002:a6b:7712:: with SMTP id n18mr32653423iom.34.1629833325227; Tue, 24 Aug 2021 12:28:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629833325; cv=none; d=google.com; s=arc-20160816; b=Pvm5dU8RQH9COSsu0U+M/wvdjw1Ecq04Srq7MbIVLYpzGFESFSBt/68wRWmci+syBm 4SldfKEUr7WEBcCYTenzzlRVRrvutcmBqT1uytHRcrZCINxHHaydx4ExYJd5GvVV6PxT PdsSsINYyrZRvrx6t+/4KjqYz/udyejz93mZ8afTQQ9ZM3lPvPc4pkt9zzfU9lZK4OiJ H+M32awk8TvtPZrwg2P7fW1AaNTQ3Y92LgZP8+CsVFN46JmW9eER31HXFzhyuJ1FBcoH n6B6QymRNfSSg0ReJcCldvHTldSnTezE2hXjjtjtIypsLjbw5ogPShShfUxWGKqzbGdS 9RBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=6h+JNdLP52k3zMbkqivoL2joVOk1AQjGMNl+Mz3dyfY=; b=lh89rMqGE6Mi3D13WSg64pboJQ65v51Cq/JsIAS5zo/tRgSZwJh2VmLYm171wf2J/+ z6AaDkf8GcUucOD8LWKIRQXzsdv3UATlQoMVsj0Ip7s+jxhqxgkpSBjztDlO4wwZVH2K P0xD5/hDeIDa8ot224vKoj8Q98GhJxZeCGDd7NxpcCCVoT/2uimje7pZrSPD1dpXDrE4 8t5oG5MAtYEUhKddlNJ12zIA+darmNMjnMlgZXOYiBRN9xVmLsyyqV1IT/FR8fGFA0T3 XTgDFtgA1hQWBtfBtlkezu17dlTlWdsVljgIKq05sh8crcrSHsyv1ELRuE5ZVO5Kqp3w cXkA== 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 q3si18557086ils.46.2021.08.24.12.28.33; Tue, 24 Aug 2021 12:28:45 -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 S234618AbhHXT2M (ORCPT + 99 others); Tue, 24 Aug 2021 15:28:12 -0400 Received: from mail-lf1-f49.google.com ([209.85.167.49]:40677 "EHLO mail-lf1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230197AbhHXT2L (ORCPT ); Tue, 24 Aug 2021 15:28:11 -0400 Received: by mail-lf1-f49.google.com with SMTP id v19so22507124lfo.7; Tue, 24 Aug 2021 12:27:26 -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=6h+JNdLP52k3zMbkqivoL2joVOk1AQjGMNl+Mz3dyfY=; b=OOhmObWIrfACoMuFk//OPvaQD8SFPaZa5zZURYCGr/htDcQJRoGuEnaNwb8SkiREPv 0/z7/oz/poq9cfdV9Nqtz4Mo+EbJ2EKrDEPmMmWznh9nSsjtfK96K0WgZguWqfG4+7o6 IQylnorMiXYKbGq2rCEXxjAzs7Lx2DxBpR8Am3xi8vZGuAVnG7KL/OfEM0F5ue7AYC4p 7zDAuUXvm0LiV0oYJ94NjuhHt1XRePElD5xpuPQCHjrnYBhWKUd/sNfqkOgbMJGXMrzV GAaMD/jf3XN0eelvnOw3LiNAhAawm2LHRz0iubnWlBb9Ol/eIDC7OYl4AUlRgaiRnXKG Gm3g== X-Gm-Message-State: AOAM533DEywlDMKIhq5etT0akJEZUlZw01gcq4i9kOT767UIc1GSl6i9 fCr+UE5F3cg8L2l97UIC79dnFSw71KEJEKnY9BQ= X-Received: by 2002:a05:6512:158e:: with SMTP id bp14mr22092115lfb.509.1629833245611; Tue, 24 Aug 2021 12:27:25 -0700 (PDT) MIME-Version: 1.0 References: <9dee672538967a3cf7e82ef194ebccc709b1af41.1629454773.git.rickyman7@gmail.com> In-Reply-To: <9dee672538967a3cf7e82ef194ebccc709b1af41.1629454773.git.rickyman7@gmail.com> From: Namhyung Kim Date: Tue, 24 Aug 2021 12:27:13 -0700 Message-ID: Subject: Re: [RFC PATCH v3 06/15] perf workqueue: introduce workqueue struct To: Riccardo Mancini Cc: Arnaldo Carvalho de Melo , Ian Rogers , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , linux-kernel , linux-perf-users , Alexey Bayduraev Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Riccardo, On Fri, Aug 20, 2021 at 3:54 AM Riccardo Mancini wrote: > +/** > + * workqueue_strerror - print message regarding lastest error in @wq > + * > + * Buffer size should be at least WORKQUEUE_STRERR_BUFSIZE bytes. > + */ > +int workqueue_strerror(struct workqueue_struct *wq, int err, char *buf, size_t size) > +{ > + int ret; > + char sbuf[THREADPOOL_STRERR_BUFSIZE], *emsg; > + const char *errno_str; > + > + errno_str = workqueue_errno_str[-err-WORKQUEUE_ERROR__OFFSET]; It seems easy to crash with an invalid err argument. > + > + switch (err) { > + case -WORKQUEUE_ERROR__POOLNEW: > + case -WORKQUEUE_ERROR__POOLEXE: > + case -WORKQUEUE_ERROR__POOLSTOP: > + case -WORKQUEUE_ERROR__POOLSTARTTHREAD: > + if (IS_ERR_OR_NULL(wq)) > + return scnprintf(buf, size, "%s: unknown.\n", > + errno_str); > + > + ret = threadpool__strerror(wq->pool, wq->pool_errno, sbuf, sizeof(sbuf)); > + if (ret < 0) > + return ret; > + return scnprintf(buf, size, "%s: %s.\n", errno_str, sbuf); > + case -WORKQUEUE_ERROR__WRITEPIPE: > + case -WORKQUEUE_ERROR__READPIPE: > + emsg = str_error_r(errno, sbuf, sizeof(sbuf)); This means the errno should be kept before calling this, right? > + return scnprintf(buf, size, "%s: %s.\n", errno_str, emsg); > + case -WORKQUEUE_ERROR__INVALIDMSG: > + return scnprintf(buf, size, "%s.\n", errno_str); > + default: > + emsg = str_error_r(err, sbuf, sizeof(sbuf)); > + return scnprintf(buf, size, "Error: %s", emsg); Newline at the end? Thanks, Namhyung > + } > +} > +