From patchwork Mon Jun 10 21:09:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 166376 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1499510ilk; Mon, 10 Jun 2019 14:09:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqz/+WJ7cIqLbNlqZADaeyWoDDI8FyDX8HnliOK6n+aiqb0lZKMEl3FUbykjYYeryQ7n8uw2 X-Received: by 2002:a17:902:25ab:: with SMTP id y40mr16065617pla.268.1560200993883; Mon, 10 Jun 2019 14:09:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560200993; cv=none; d=google.com; s=arc-20160816; b=LpmII1x/Iw3FXK74KrEa72FmU2ltjTVEjlM7Mg6IO+r2/GTVc/9nyBsqsoyVO6NdiB uJ63QCg+dAX5+HS9EGNxiVu6f+9PmpgJpR19l2/d5C9+76YBAjkgU0t6E9oPAkpvXGrd pWw1NbOb0uI6fY/BKazGPCQbsqx3KlDw3LAmLgSQLKyF8zrK29F5Na1P88DPaH+j6MIA 9rKca0Swnq+AxhuCJf6nM7aycI4vMLCPqnqG26pmNAQW5h7IP563gxFZhzEvWv6XYAIO NLuGQ3vrs3GRb3uGeI5dYakCcqzmLV54hvZLXfb4FMey6CCMtWKhSfz4KR/W6WjTwAvz bBTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=gBHuB2VNJ5k6YmFjVqedIpm8iZuBjeT1LQUHDwfjGnA=; b=eGNhuCJw2ga6cOPfRPHOXVJZvUlXyyOoQ8S6r7ouJYMo5eZ8G2nAxhJz10LXMwLxcb eSSNpyrZFJY7Jr0iifILZkB3uYxW7Jz94WuZku/9W7BRh2Jh5Dju47dmB68mIXINSffq +1WmBrz470iAASZfgafIMI4u0/Y+W8m7UQZSKB0t5jrsx8KNQ2UeUZXd7wZLTdsaoM5c uUG/eZqP2BSmtCF8ZlErrdbBPNgEuse0p0ZCD0FVNP7sirMO8RLWgyeSoC+wBkWXD8cC fKWSDzQLWj/tt5iznHuATtinu1vBw/MICNiKP4Y30qCSOErr+YOFbJ39VtMo9trYTTLp AlAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=QxjEJROh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f193si11079730pgc.144.2019.06.10.14.09.53; Mon, 10 Jun 2019 14:09:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=QxjEJROh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389986AbfFJVJw (ORCPT + 30 others); Mon, 10 Jun 2019 17:09:52 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:33663 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726663AbfFJVJw (ORCPT ); Mon, 10 Jun 2019 17:09:52 -0400 Received: from grover.flets-west.jp (softbank126125154139.bbtec.net [126.125.154.139]) (authenticated) by conuserg-10.nifty.com with ESMTP id x5AL9Tug023067; Tue, 11 Jun 2019 06:09:29 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com x5AL9Tug023067 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1560200970; bh=gBHuB2VNJ5k6YmFjVqedIpm8iZuBjeT1LQUHDwfjGnA=; h=From:To:Cc:Subject:Date:From; b=QxjEJROhZTUj4Ngn88siuPtMJPW5B+uaonsOC3pKbYu1DQgOy8kC/YmI1fQBpbrBF S2x3ROIR4K6XnyRKjAnY2wOK3B2WhFZ+bikXYoMVdhBL4XMn65NSffWqxWijegpvw2 mdCVcupWQWMhvfIOPr2AofH4L5kPPUnKkg6j5vMtGG11eFDL+8ecPQEgC4Pkk0JjBo oDZgcoqtxaprFNkatHWXfh2Lnn7sjXj/uU/cEFDXpd8z8fpAvKh6+MDbHjFtMRVxcB VDgaUa0V03VEUy3xx99FzDd1FqJf5rKqBLvKzESlZhf4NhIVA1AK3fs4J7rw/JOadr lXMcApWEqtS0Q== X-Nifty-SrcIP: [126.125.154.139] From: Masahiro Yamada To: Greg Kroah-Hartman Cc: "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, Masahiro Yamada , "Rafael J. Wysocki" Subject: [PATCH v2] kobject: return -ENOSPC when add_uevent_var() fails Date: Tue, 11 Jun 2019 06:09:24 +0900 Message-Id: <20190610210924.9514-1-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This function never attempts to allocate memory, so returning -ENOMEM looks weird to me. The reason of the failure is there is no more space in the given kobj_uevent_env structure. Let's change the error code to -ENOSPC. This patch is safe since this function had never failed in reality. The callers of this function put a fixed number of small strings into the buffer. The buffer is defined to be large enough: #define UEVENT_NUM_ENVP 32 /* number of env pointers */ #define UEVENT_BUFFER_SIZE 2048 /* buffer for the variables */ As you see WARN() in the error paths, any failure of this function is a software bug. If such a case had ever happened before, you would have already seen a noisy back-trace, then you would have increased UEVENT_NUM_ENVP or UEVENT_BUFFER_SIZE. Nobody has ever increased UEVENT_NUM_ENVP or UEVENT_BUFFER_SIZE since their addition, that is, this structure is always large enough. Signed-off-by: Masahiro Yamada --- Changes in v2: - Rephrase the commit log. No code change. lib/kobject_uevent.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c index 7998affa45d4..5ffd44bf4aad 100644 --- a/lib/kobject_uevent.c +++ b/lib/kobject_uevent.c @@ -647,7 +647,7 @@ EXPORT_SYMBOL_GPL(kobject_uevent); * @env: environment buffer structure * @format: printf format for the key=value pair * - * Returns 0 if environment variable was added successfully or -ENOMEM + * Returns 0 if environment variable was added successfully or -ENOSPC * if no space was available. */ int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...) @@ -657,7 +657,7 @@ int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...) if (env->envp_idx >= ARRAY_SIZE(env->envp)) { WARN(1, KERN_ERR "add_uevent_var: too many keys\n"); - return -ENOMEM; + return -ENOSPC; } va_start(args, format); @@ -668,7 +668,7 @@ int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...) if (len >= (sizeof(env->buf) - env->buflen)) { WARN(1, KERN_ERR "add_uevent_var: buffer size too small\n"); - return -ENOMEM; + return -ENOSPC; } env->envp[env->envp_idx++] = &env->buf[env->buflen];