From patchwork Tue Oct 1 12:17: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: 174857 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp8463463ill; Tue, 1 Oct 2019 05:17:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqw/mA9Xybr1e/1o8VFYMnUs5VaIzYWS/gGfbqPB4/v5NcF6AXJJifm0vPZsXFdzcuUadiiZ X-Received: by 2002:a50:b582:: with SMTP id a2mr25412031ede.98.1569932276282; Tue, 01 Oct 2019 05:17:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569932276; cv=none; d=google.com; s=arc-20160816; b=VB8b8NChG5IBUwh22a1rX0uixTshHIcXM9kgBDDQ+OP4VxMI9wSgpmIlj+2/FwvzWv 9uHA6iD2MESSYyBR/p4GM/Dwb7XbaxqNB/2zW/Ed0TtRuvhkBytayop7dXAwz+NdIrOU jTqU0siec1qoxoGd6suxum762D9ew50oADFjhqnVIuvxznN0nX3JXcqyvX1AwxjKg0fb tt3+GvpusE82ppr+U+n6y2IsXCFd7/UihOJs2OrKXYySTdHWFceRDWx+czKrCVUID0Dw /n/lj+3lJQP+mv8lfjscC44Le7EYRWqVdmVVJW3i7L/9/+hytFwOkvPRy4YMkjX0a/wS x7rA== 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=9hkjCrWAmYl8Hzn0M9NoT02tNI9xvkz9T7RGu9HJXvc=; b=AwHJN9ZvSP3Acyj895bnTzfGN2Z90rWvJIycMbfpLDqEU9QrTFMkOBM6aSssItrCa+ qDprGmb889xJ3xLsw7x3dV/NKqlx9yryLmh5Lel1bRYa2vOLRWj6fhZiP4SofVJqJx5c 1RqUs8JfaVkTn0hmZS1rCgD8k3rBzcaUBF9EyLkZo0/bFeJZt8SHjxQoslhlYCCGqOmz VuZIpVCHgJlMZsp0NG/FVmUPBr1ENNj/JivaGSa6BslJ6prnQI4p2amIEbuoij9S13by n9ggfs9hCJVZ2nY697+kJt9b0lEM0SNbatv9zO6VFFlf4Eu60yTmV673PCngsJIfhapF l3Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Zf3xvtMO; 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 e43si9415887eda.296.2019.10.01.05.17.55; Tue, 01 Oct 2019 05:17:56 -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=Zf3xvtMO; 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 S2387691AbfJAMRz (ORCPT + 27 others); Tue, 1 Oct 2019 08:17:55 -0400 Received: from conuserg-11.nifty.com ([210.131.2.78]:24482 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725821AbfJAMRy (ORCPT ); Tue, 1 Oct 2019 08:17:54 -0400 Received: from localhost.localdomain (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-11.nifty.com with ESMTP id x91CHO42014561; Tue, 1 Oct 2019 21:17:25 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com x91CHO42014561 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1569932245; bh=9hkjCrWAmYl8Hzn0M9NoT02tNI9xvkz9T7RGu9HJXvc=; h=From:To:Cc:Subject:Date:From; b=Zf3xvtMOcFMOqPb9lalb7aEUjRdygqtb2++Le+8tL3Kaq7nkVQOusOBJ8NVu0EqsT 2n7pO1I8k6auJdH+vPDQU4XrIB9MQuHXzzTk4HaenQmd5bnWZEw4gacZKl8863tMe/ r8tRagTROlRnbNCW3J/HmHF5Er3DLB9ylWlqs6IY9u79cRbKVQH4IN7loOS3Qo161t cl+1+x35XjFPETe1cNvOJBTE0JL2YaR5VyozetocY3RKG+TogOCNNXPUjx7XSbn9oz CgT16ihKjVklfdonOR2Hh0qMsTEUOsvvnalMZkn36aCDDAEoyJzXRoNQM2DwuGo6Ck mIPcyxCuc8U5Q== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kernel@vger.kernel.org Cc: Geert Uytterhoeven , Masahiro Yamada Subject: [PATCH] scripts/setlocalversion: clear local varaible to make it work for sh Date: Tue, 1 Oct 2019 21:17:24 +0900 Message-Id: <20191001121724.23886-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 Geert Uytterhoeven reports a strange side-effect of commit 858805b336be ("kbuild: add $(BASH) to run scripts with bash-extension"), which inserts the contents of a localversion file in the build directory twice. [Steps to Reproduce] $ echo bar > localversion $ mkdir build $ cd build/ $ echo foo > localversion $ make -s -f ../Makefile defconfig include/config/kernel.release $ cat include/config/kernel.release 5.4.0-rc1foofoobar This comes down to the behavior change of 'local' variables. The 'man sh' on my Ubuntu machine, where sh is an alias to dash, explains as follows: When a variable is made local, it inherits the initial value and exported and readonly flags from the variable with the same name in the surrounding scope, if there is one. Otherwise, the variable is initially unset. [Test Code] foo () { local res echo "res: $res" } res=1 foo [Result] $ sh test.sh res: 1 $ bash test.sh res: So, scripts/setlocalversion correctly works only for bash in spite of its hashbang being #!/bin/sh. Nobody had noticed it before because CONFIG_SHELL was previously set to sh only when bash is missing, which is very unlikely to happen. The benefit of commit 858805b336be is to make people write portable and correct code. I gave it the Fixes tag since it uncovered the issue for most of people. Clear the variable 'res' in collect_files() to make it work for sh (and it also works on distributions where sh is an alias to bash). Fixes: commit 858805b336be ("kbuild: add $(BASH) to run scripts with bash-extension") Reported-by: Geert Uytterhoeven Signed-off-by: Masahiro Yamada --- scripts/setlocalversion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.17.1 Tested-by: Geert Uytterhoeven diff --git a/scripts/setlocalversion b/scripts/setlocalversion index 365b3c2b8f43..220dae0db3f1 100755 --- a/scripts/setlocalversion +++ b/scripts/setlocalversion @@ -126,7 +126,7 @@ scm_version() collect_files() { - local file res + local file res= for file; do case "$file" in