From patchwork Mon Oct 14 07:07:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 176132 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp4141492ill; Mon, 14 Oct 2019 00:08:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZjSoVBmBBioIqY1nTLMXO2xyYrEl8fHbVMm3A2zhDNnxdsmAkTImTYayMGQoEU3Lazbwr X-Received: by 2002:a17:906:1911:: with SMTP id a17mr26801653eje.14.1571036906964; Mon, 14 Oct 2019 00:08:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571036906; cv=none; d=google.com; s=arc-20160816; b=sB4SGYixJVsiQLWfMO4wBNR7zSi2oudLG157e8VQSOduDdJgcK8ln5RvblIVVq8TeR 9Hc9I0k1W084WLAmNQcSBpjShdbNBuEdZc0l1DC73xvDWP97J9dslsiIgKJhqnX8ughU RZ6F21iB/XBUAz3J0OJ/26J7E9Vbxo3XW43iFLIWIXmQBZ4W3rbGEbh2PDtNmXiLCwYq ym4nPPTkcWdrEvpDicJyk4dC5Z5S//NEIp4g7iIwTsiq7aV5QVYhumCDpNaGTUcTq02T 1SuA1zzAuHPHWQJZk7KqH/pOapSDJOUfJqSLHHyZRqkZFX9aWEXbq6shqLSox+juYmQn 4+JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=1ydsP1Cp9s0wk741A+j1HGA3H7t+pJBn7+BclAM8H+M=; b=C14NAGijaCcQBJecBcyksOmUBtwnb5aBTj72TfpiquRxZV6GeZvBMYD/1Y9zO+Nzl2 wKjN1PxpWS1LlRMuyMZ8iTUOqwTObBfsHkeoT20zRhImBCsbez6hOR2MIvm/EPx3RHw8 tGNzRl269t7scwG/Ito9EndriVFCiLAKFHIacMKffh/FkoXxL+lVjkqo7MBfj3ecdC15 KQ8mbcJb6WONPWVB1yuDV/Gpp7C7OpVQ4TfEAQK5nF5Ro5WKydvJwjMg33agnk2NzC3S wmHtwBEbIGpXMy2/bTM6Ju3kjUdApFhFeNR5mEdV5d7g+PpGpOiVoGsEg4s3gdNDuo8o n8jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kahd71I+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t18si10584853ejr.205.2019.10.14.00.08.26; Mon, 14 Oct 2019 00:08:26 -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=@linaro.org header.s=google header.b=kahd71I+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730271AbfJNHIU (ORCPT + 10 others); Mon, 14 Oct 2019 03:08:20 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34634 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730263AbfJNHIU (ORCPT ); Mon, 14 Oct 2019 03:08:20 -0400 Received: by mail-pf1-f195.google.com with SMTP id b128so9872190pfa.1 for ; Mon, 14 Oct 2019 00:08:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=1ydsP1Cp9s0wk741A+j1HGA3H7t+pJBn7+BclAM8H+M=; b=kahd71I+jydL8AwtKPA5jqJIFN6xTV+kelQ8RxPi/IoS5FJswOPifHzuka0ajgk84D Tu/kAVwgphcFPtLaj+ifYHJt6yGsuDBOZ9YiNQIiRoVQYgrzloEfXdpt7jEJvjvQigkC 7J224xdekYFogIev6qsKXWkQLj8f+B/jIWJRAeOiE5dmZSmnQyTZ29/sT5qNyrrmNm/X MiX7W3pwbwf4mckEbkQBSzTufBV4PzkHHmtN6LMVL223bCC1b5NkoQ2+YKnGWwdggELX QQZcbbRER3Lpt9PjdGQPnB6IVsyfV6hpzC/LfZ6670MitRmRNIJPiMNunqSEpw0pdfli WneA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=1ydsP1Cp9s0wk741A+j1HGA3H7t+pJBn7+BclAM8H+M=; b=XI9y7tZQtFHmgOcfULDLySAfnBS8ceBsm5CKDuatrS6Leq1x1mIaQpFd8thZTwlpE6 3m/qjyF2KxCSep8zkJ/AQAFUT8DrABO+qoBG7vof70IBhJ8gQXFFBIsb4Jw5j6kjX980 ot1cnmq2IbSSpovws1U+fFyoiNbkf1/OmMq3FVZkPzmgjSDnEA7Yu/kFl+7RD51x9HEM WJyR3UsIBAu3jHuybdZFFBCLELayceRo6vQJGeIjW0Qz0kYwEuYRkGOQ1rMcvTuur3cy AFBcaED3tWhnblM5SZa6qsqT7kce4QhB7ycCFkAEr7P92KLwsmW203k8PCZOyzUG37IX qbUA== X-Gm-Message-State: APjAAAVGfDq2gh7ntRs7+5yiStXFmv4nGgbaIdeUm1io0kpAYs3YbtXH 3z9lyBm9hBilfPwpLaFK1SrSYw== X-Received: by 2002:a63:5022:: with SMTP id e34mr15455176pgb.400.1571036898239; Mon, 14 Oct 2019 00:08:18 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id p190sm20619948pfb.160.2019.10.14.00.08.14 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Oct 2019 00:08:17 -0700 (PDT) From: Baolin Wang To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: linus.walleij@linaro.org, orsonzhai@gmail.com, zhang.lyra@gmail.com, baolin.wang@linaro.org, linux-arm-kernel@lists.infradead.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] hwspinlock: Remove BUG_ON() from the hwspinlock core Date: Mon, 14 Oct 2019 15:07:43 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The original code use BUG_ON() to validate the parameters when locking or unlocking one hardware lock, but we should not crash the whole kernel though the hwlock parameters are incorrect, instead we can return the error number for users and give some warning. Signed-off-by: Baolin Wang --- drivers/hwspinlock/hwspinlock_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- 1.7.9.5 diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c index 8862445..a22e252c 100644 --- a/drivers/hwspinlock/hwspinlock_core.c +++ b/drivers/hwspinlock/hwspinlock_core.c @@ -92,8 +92,8 @@ int __hwspin_trylock(struct hwspinlock *hwlock, int mode, unsigned long *flags) { int ret; - BUG_ON(!hwlock); - BUG_ON(!flags && mode == HWLOCK_IRQSTATE); + if (WARN_ON(!hwlock || (!flags && mode == HWLOCK_IRQSTATE))) + return -EINVAL; /* * This spin_lock{_irq, _irqsave} serves three purposes: @@ -264,8 +264,8 @@ int __hwspin_lock_timeout(struct hwspinlock *hwlock, unsigned int to, */ void __hwspin_unlock(struct hwspinlock *hwlock, int mode, unsigned long *flags) { - BUG_ON(!hwlock); - BUG_ON(!flags && mode == HWLOCK_IRQSTATE); + if (WARN_ON(!hwlock || (!flags && mode == HWLOCK_IRQSTATE))) + return; /* * We must make sure that memory operations (both reads and writes),