From patchwork Tue Jun 16 10:14:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu \(Google\)" X-Patchwork-Id: 224541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 144BEC433DF for ; Tue, 16 Jun 2020 10:14:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E3E2920786 for ; Tue, 16 Jun 2020 10:14:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592302452; bh=yZgg/X3OtqsCUMSqbPqhvaERebP2JWDOcMpre3GtJuw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=m3q/eenE2U5bKnARxAVZOHBg5UwEXCmzuJkOLLFcvg2OH5HMH8ZPZFE08lU5pCV0A XDWASsQ+q+sU5ozdAktPZwEsdMhR3RqyjW2csBO6kxebgXSUqiTG99Caabp9Bmg73Z WChofWNptziWTPlSdmuMQWQYG7twazfvKouYxXhk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727804AbgFPKOM (ORCPT ); Tue, 16 Jun 2020 06:14:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:41348 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726052AbgFPKOM (ORCPT ); Tue, 16 Jun 2020 06:14:12 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9DDE920767; Tue, 16 Jun 2020 10:14:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592302451; bh=yZgg/X3OtqsCUMSqbPqhvaERebP2JWDOcMpre3GtJuw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CeeIZO/Fvb74m3oLaMMUZ0SWj3SoBaps66trqTRJx7OWzcaLD4so3qttEFXJ2ZSOG kQzkyO9JqvODQbStbVk3o4C/pj8aSEPU2wiAcjjVSH3iZ2lEQ0cnrRybGDoOi6U1Yd 4j4BhVsPNIlqa/wVKO1OtLWlLM47n33gy5+KjQjg= From: Masami Hiramatsu To: Steven Rostedt Cc: stable@vger.kernel.org, LKML Subject: [PATCH v2 1/4] proc/bootconfig: Fix to use correct quotes for value Date: Tue, 16 Jun 2020 19:14:08 +0900 Message-Id: <159230244786.65555.3763894451251622488.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <159230243779.65555.11413773790099102781.stgit@devnote2> References: <159230243779.65555.11413773790099102781.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Fix /proc/bootconfig to select double or single quotes corrctly according to the value. If a bootconfig value includes a double quote character, we must use single-quotes to quote that value. This modifies if() condition and blocks for avoiding double-quote in value check in 2 places. Anyway, since xbc_array_for_each_value() can handle the array which has a single node correctly. Thus, if (vnode && xbc_node_is_array(vnode)) { xbc_array_for_each_value(vnode) /* vnode->next != NULL */ ... } else { snprintf(val); /* val is an empty string if !vnode */ } is equivalent to if (vnode) { xbc_array_for_each_value(vnode) /* vnode->next can be NULL */ ... } else { snprintf(""); /* value is always empty */ } Fixes: c1a3c36017d4 ("proc: bootconfig: Add /proc/bootconfig to show boot config list") Cc: stable@vger.kernel.org Signed-off-by: Masami Hiramatsu --- Changes in v2: - Sort local vars definition as upside-down xmas tree format. - Fix patch description (typo and add comments) --- fs/proc/bootconfig.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/proc/bootconfig.c b/fs/proc/bootconfig.c index 9955d75c0585..ad31ec4ad627 100644 --- a/fs/proc/bootconfig.c +++ b/fs/proc/bootconfig.c @@ -26,8 +26,9 @@ static int boot_config_proc_show(struct seq_file *m, void *v) static int __init copy_xbc_key_value_list(char *dst, size_t size) { struct xbc_node *leaf, *vnode; - const char *val; char *key, *end = dst + size; + const char *val; + char q; int ret = 0; key = kzalloc(XBC_KEYLEN_MAX, GFP_KERNEL); @@ -41,16 +42,20 @@ static int __init copy_xbc_key_value_list(char *dst, size_t size) break; dst += ret; vnode = xbc_node_get_child(leaf); - if (vnode && xbc_node_is_array(vnode)) { + if (vnode) { xbc_array_for_each_value(vnode, val) { - ret = snprintf(dst, rest(dst, end), "\"%s\"%s", - val, vnode->next ? ", " : "\n"); + if (strchr(val, '"')) + q = '\''; + else + q = '"'; + ret = snprintf(dst, rest(dst, end), "%c%s%c%s", + q, val, q, vnode->next ? ", " : "\n"); if (ret < 0) goto out; dst += ret; } } else { - ret = snprintf(dst, rest(dst, end), "\"%s\"\n", val); + ret = snprintf(dst, rest(dst, end), "\"\"\n"); if (ret < 0) break; dst += ret; From patchwork Tue Jun 16 10:14:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu \(Google\)" X-Patchwork-Id: 224540 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2D15C433E0 for ; Tue, 16 Jun 2020 10:14:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 693E820707 for ; Tue, 16 Jun 2020 10:14:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592302474; bh=UXfCyP+Xp14GVhxH+a3ULCFKGys2vq8CRdRVm47yCYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Ig/Sto6PBULOC4DrFhieDxZ1Em74wVG3QzzJaCthL//sXImZ3ygv7z6F5/LoV5vBO S1EpUWANE08EFm80x1GuSeW/CysHQ5tyY36vbPw2Xqy1qp0DWFpkKfTodyp7cAafZ1 Atvp29mhwZXn2v9ivQWZHnCY84N31RV2TYX2IBW8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728357AbgFPKO3 (ORCPT ); Tue, 16 Jun 2020 06:14:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:41592 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726052AbgFPKO3 (ORCPT ); Tue, 16 Jun 2020 06:14:29 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0CED320734; Tue, 16 Jun 2020 10:14:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592302468; bh=UXfCyP+Xp14GVhxH+a3ULCFKGys2vq8CRdRVm47yCYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0eSIpaJLvTtQWq2UAwb171QD2F/yQpSdGBSMbkC+lgOZvbJMUk9IQqDZ/SKOaN5gx CLRBqlNUq9cW4p8PCIjD3iJXa63eMNdQUGsOdqs2yiXgNLPt1QiCrOE6uP4h/dQe/H t1ObfSKLy5Ky2aJ4sqp0lRgJ4++Pny4n1pxboa9Y= From: Masami Hiramatsu To: Steven Rostedt Cc: stable@vger.kernel.org, LKML Subject: [PATCH v2 3/4] tools/bootconfig: Fix to return 0 if succeeded to show the bootconfig Date: Tue, 16 Jun 2020 19:14:25 +0900 Message-Id: <159230246566.65555.11891772258543514487.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <159230243779.65555.11413773790099102781.stgit@devnote2> References: <159230243779.65555.11413773790099102781.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Fix bootconfig to return 0 if succeeded to show the bootconfig in initrd. Without this fix, "bootconfig INITRD" command returns !0 even if the command succeeded to show the bootconfig. Fixes: 950313ebf79c ("tools: bootconfig: Add bootconfig command") Cc: stable@vger.kernel.org Signed-off-by: Masami Hiramatsu --- Changes in v2: - Use goto for better reading. --- tools/bootconfig/main.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c index 21896a6675fd..e0878f5f74b1 100644 --- a/tools/bootconfig/main.c +++ b/tools/bootconfig/main.c @@ -207,11 +207,13 @@ int show_xbc(const char *path) } ret = load_xbc_from_initrd(fd, &buf); - if (ret < 0) + if (ret < 0) { pr_err("Failed to load a boot config from initrd: %d\n", ret); - else - xbc_show_compact_tree(); - + goto out; + } + xbc_show_compact_tree(); + ret = 0; +out: close(fd); free(buf);