From patchwork Fri Dec 1 15:29:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 120351 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1284783qgn; Fri, 1 Dec 2017 07:29:39 -0800 (PST) X-Google-Smtp-Source: AGs4zMZws3uEBGi+Adxhd4mt2PPUmDiyTEuqxN3ZqaLpJI+4b624yFrxK5/fH5h7z9s1Gvjfkx48 X-Received: by 10.98.139.138 with SMTP id e10mr10737699pfl.231.1512142179807; Fri, 01 Dec 2017 07:29:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512142179; cv=none; d=google.com; s=arc-20160816; b=ubtI1zLuk5/bdkM+26h3/Oxr2b8U+/VyoGJXEUvNfbBk8imj2Z2Ur53FpJRFc2jemX Vv63Jk3bvCVAq/E0MhTe4iShzxJKzxJwsim7LgqQhvWKMddDiuWOVeWseBIsgxR3jNMU IWghAeyOE3QgfcRj8GpSbWf1H0tih4ECG2LZfLOY5nJoRAuYKisPLuqGEuBEg6KRWJmH 0RZmDeSu84p40OBPAWCj+syi7NQnXWKYUJDk4Djf9gzdiLVwzv2Uz6R2zBcpfDEcokXs AmoaKxCUEscYXJy3VQTI/7dU7HRgIWAzIuUKMICrkHU7Ht7Gio19R2ac8MQHQtf+kRRY DBZg== 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 :arc-authentication-results; bh=GrHJbkFCHwSQ+OPg0kFtmJTdZUZ9d0GhyDGrkkewM+c=; b=TG3uufkLyHBQc91qAPK6w6tQ8BgXcGvCPJhDtBZcrv/nS8wIOyD3wRdB9ILut8sBwu /41ASG3KFGL8U/uEoMGq2/Ysgs7Wl1OJlH0xwmMF2IRbexKqzEJZQXOWtSPj08mx9O6d wERqopFVO4/UMYBoNcYEb0hpoG8tiNMRUAVNy0T55+wdgw81kIOyjaEL4s+mtW7b7Lzh MWQGp5a8oGkDEtoc9/pdq1GaqIfsVi1buhMjlNisSBiklb2EnKQj5CYkL+Yc1o3lK2TZ 0HvxZ7GmtgaVol5uyyqR4U7/d7EWCpn1tK4npWOfdrczd+l8Mjen88AE5mxKK3ycCBqW XW4A== ARC-Authentication-Results: i=1; mx.google.com; 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 w24si1430838pll.241.2017.12.01.07.29.39; Fri, 01 Dec 2017 07:29:39 -0800 (PST) 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; 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 S1752298AbdLAP3i (ORCPT + 28 others); Fri, 1 Dec 2017 10:29:38 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:42522 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751319AbdLAP3g (ORCPT ); Fri, 1 Dec 2017 10:29:36 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7DE0680D; Fri, 1 Dec 2017 07:29:36 -0800 (PST) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4D72D3F246; Fri, 1 Dec 2017 07:29:36 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id F2F8C1AE3D69; Fri, 1 Dec 2017 15:29:39 +0000 (GMT) From: Will Deacon To: tglx@linutronix.de Cc: marc.zyngier@arm.com, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, Will Deacon Subject: [PATCH] irqdesc: Use bool return type instead of int Date: Fri, 1 Dec 2017 15:29:39 +0000 Message-Id: <1512142179-24616-1-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The irq_balancing_disabled and irq_is_percpu{,_devid} functions are clearly intended to return bool like the functions in kernel/irq/settings.h, but actually return an int containing a masked value of desc->status_use_accessors. This can lead to subtle breakage if, for example, the return value is subsequently truncated when assigned to a narrower type. As Linus points out: | In particular, what can (and _has_ happened) is that people end up | using these functions that return true or false, and they assign the | result to something like a bitfield (or a char) or whatever. | | And the code looks *obviously* correct, when you have things like | | dev->percpu = irq_is_percpu_devid(dev->irq); | | and that "percpu" thing is just one status bit among many. It may even | *work*, because maybe that "percpu" flag ends up not being all that | important, or it just happens to never be set on the particular | hardware that people end up testing. | | But while it looks obviously correct, and might even work, it's really | fundamentally broken. Because that "true or false" function didn't | actually return 0/1, it returned 0 or 0x20000. | | And 0x20000 may not fit in a bitmask or a "char" or whatever. Fix the problem by consistently using bool as the return type for these functions. Reported-by: Linus Torvalds Signed-off-by: Will Deacon --- include/linux/irqdesc.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 2.1.4 diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h index dd418955962b..39fb3700f7a9 100644 --- a/include/linux/irqdesc.h +++ b/include/linux/irqdesc.h @@ -230,7 +230,7 @@ irq_set_chip_handler_name_locked(struct irq_data *data, struct irq_chip *chip, data->chip = chip; } -static inline int irq_balancing_disabled(unsigned int irq) +static inline bool irq_balancing_disabled(unsigned int irq) { struct irq_desc *desc; @@ -238,7 +238,7 @@ static inline int irq_balancing_disabled(unsigned int irq) return desc->status_use_accessors & IRQ_NO_BALANCING_MASK; } -static inline int irq_is_percpu(unsigned int irq) +static inline bool irq_is_percpu(unsigned int irq) { struct irq_desc *desc; @@ -246,7 +246,7 @@ static inline int irq_is_percpu(unsigned int irq) return desc->status_use_accessors & IRQ_PER_CPU; } -static inline int irq_is_percpu_devid(unsigned int irq) +static inline bool irq_is_percpu_devid(unsigned int irq) { struct irq_desc *desc;