From patchwork Sat Jul 9 17:01:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arvind Yadav X-Patchwork-Id: 9222139 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D9EA860467 for ; Sat, 9 Jul 2016 17:02:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C85C02894F for ; Sat, 9 Jul 2016 17:02:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCF3E28951; Sat, 9 Jul 2016 17:02:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6162D2894F for ; Sat, 9 Jul 2016 17:02:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933120AbcGIRBo (ORCPT ); Sat, 9 Jul 2016 13:01:44 -0400 Received: from 51.23-broadband.acttv.in ([106.51.23.179]:21157 "EHLO arvind-ThinkPad-Edge-E431" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S933094AbcGIRBn (ORCPT ); Sat, 9 Jul 2016 13:01:43 -0400 Received: by arvind-ThinkPad-Edge-E431 (Postfix, from userid 1000) id 284BF4E0856; Sat, 9 Jul 2016 22:31:38 +0530 (IST) From: Arvind Yadav To: zajec5@gmail.com Cc: viresh.kumar@linaro.org, akpm@linux-foundation.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linville@tuxdriver.com, Arvind Yadav Subject: [v2] ErrHandling:Make IS_ERR_VALUE_U32 as generic API to avoid IS_ERR_VALUE abuses. Date: Sat, 9 Jul 2016 22:31:36 +0530 Message-Id: <1468083696-15283-1-git-send-email-arvind.yadav.cs@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP IS_ERR_VALUE() assumes that its parameter is an unsigned long. It can not be used to check if an 'unsigned int' reflects an error. As they pass an 'unsigned int' into a function that takes an 'unsigned long' argument. This happens to work because the type is sign-extended on 64-bit architectures before it gets converted into an unsigned type. However, anything that passes an 'unsigned short' or 'unsigned int' argument into IS_ERR_VALUE() is guaranteed to be broken, as are 8-bit integers and types that are wider than 'unsigned long'. It would be nice to any users that are not passing 'unsigned int' arguments. Signed-off-by: Arvind Yadav --- drivers/bcma/scan.c | 1 - include/linux/err.h | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/bcma/scan.c b/drivers/bcma/scan.c index 4a2d1b2..3bc77eb 100644 --- a/drivers/bcma/scan.c +++ b/drivers/bcma/scan.c @@ -272,7 +272,6 @@ static struct bcma_device *bcma_find_core_reverse(struct bcma_bus *bus, u16 core return NULL; } -#define IS_ERR_VALUE_U32(x) ((x) >= (u32)-MAX_ERRNO) static int bcma_get_next_core(struct bcma_bus *bus, u32 __iomem **eromptr, struct bcma_device_id *match, int core_num, diff --git a/include/linux/err.h b/include/linux/err.h index 1e35588..e05a63d 100644 --- a/include/linux/err.h +++ b/include/linux/err.h @@ -20,6 +20,8 @@ #define IS_ERR_VALUE(x) unlikely((unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO) +#define IS_ERR_VALUE_U32(x) unlikely((unsigned int)(x) >= (unsigned int)-MAX_ERRNO) + static inline void * __must_check ERR_PTR(long error) { return (void *) error;