Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753307AbdI1OKj (ORCPT ); Thu, 28 Sep 2017 10:10:39 -0400 Received: from mail-by2nam03on0065.outbound.protection.outlook.com ([104.47.42.65]:8165 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751953AbdI1OKg (ORCPT ); Thu, 28 Sep 2017 10:10:36 -0400 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; From: Ioana Radulescu To: CC: , , , , , , , , , Subject: [PATCH v2] staging: fsl-mc/dpio: Fix incorrect comparison Date: Thu, 28 Sep 2017 09:10:33 -0500 Message-ID: <20170928141033.6913-1-ruxandra.radulescu@nxp.com> X-Mailer: git-send-email 2.11.0 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131510814351170731;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(336005)(7966004)(39380400002)(39860400002)(346002)(376002)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(50466002)(48376002)(68736007)(1076002)(8936002)(39060400002)(85426001)(8656003)(4326008)(2906002)(6916009)(106466001)(316002)(16586007)(54906003)(81166006)(104016004)(8676002)(81156014)(2351001)(36756003)(50226002)(356003)(498600001)(47776003)(50986999)(189998001)(77096006)(86362001)(105606002)(305945005)(97736004)(33646002)(5660300001)(7416002)(5003940100001)(53936002);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR03MB2693;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11OLC013;1:QNNR8G8pZPmBHbTSk/4GkJeStkIPGzRw6+azPA7TPkAJ4u55vFJRym9V/xQpG1n3DmuYItHp0jQ7Nck8xvAnqAdgFkGkC7YMREMUZ4M75/eKO+6pE73ZJHzDoPLu9gJV MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 489fe435-cc7a-4a5e-1cab-08d5067aaffd X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017052603199)(201703131430075)(201703131517081);SRVR:CY4PR03MB2693; X-Microsoft-Exchange-Diagnostics: 1;CY4PR03MB2693;3:xepvdHWOi3DV0amMQg/2YhqMAjhc5Id0Za85VMig2z5IURIzBBuRu80EgatGq+e4U12/71D8sFXXIaQljC3vJslmn0/W+GgkJQ16yz/a1VkeaQdiFl2rvJRSKX0AwthEHzrIKEMrcYHlPlkdDT7oxq+AjDwqcJY+bNDf4cllF5g8RqPNbdC0zQj/f5HgqtSFDf5Sxct9PvjrgS5GNYetiDC/w/SvisJqgix8Il0ucfbMME7p7puzX/B9MTW9NYMD8zMT5zgUp/KhcIB0EAROqSQpzXnmKyPPLCh/OHOSzG7mFXshqBjS0d/jUYjYj3FgA0VIAJJS1GdVy0hi9kFHMjhgZIS0dBZOWxtKwja+4qs=;25:P0oGGvrJRQK1o4gdl8tOGcd6XIPJepL7Ol61afcnoohlXDMOR5gfwSW6VcjUac49yuGzXLVlKd8PTO3RwcmERXLWVMtuqgK2TE9t3DRUJJgA1JHYqABpyijqU2JXtd4FohKgcB4CC87KXtMwtmHZPlQ3y9feu+Dfrdlgb4f2hKYOlq4WRdvjVyXR2vaPFSLN8xkbStbKxa6HAitjL0PY3IoElA4kujQ+ecO24Eq//4Y53yXiqj1A7VsZP73gK1wtexV132kOp2U9JOLzfwga4Aj+TWkUPGt+lsOlaQlE7WBRlt3GZ9f5hFmXka2US1yjA8Qh0OZ2oJfdcleyBKV/WA== X-MS-TrafficTypeDiagnostic: CY4PR03MB2693: X-Microsoft-Exchange-Diagnostics: 1;CY4PR03MB2693;31:FlxHi5r6yix5SW+OCkshG27H0ETPJQfmwgnuobTdffR7cgrAG21BBwJVXZV0dOrIkgb2vpXYwx+3V/OyJsg9bz0Erzki7abANEBdlllasT3cZajtIO5qC6w1knZEZ7hWfJiwu1MCTwJQO/NhwjtJH4xhbKsMuItxeQgYeAZapgPzv5GNTVRLIdxIIkA20Xqmk09d8Vjz1fur6+vwpNZeSoIOjMRHwEYBFPqdBDB4qqg=;4:vbGT4r48Lh140wZynQby2ahVgOOcyNl2fctS9r2pdQTzOcrkO4B2jX385g2E5+CWmC3+XJQ46rNQMKutMtTq4zj7JD1p0M8e+CTS2mpOietjbFtysJQKa1Aiz11YoW86lsPI5/mk6P/4C/Z0Z3D00157XQCKBzssJJEw/VbXoG4KPnYGmWJZkgQvmpTNa1InZIDwiY6jObolXkOVVxCcYNzKwygghAKN70I/2eVlme+Q3JRYudn8a/5YFO5AlVb2hs32bfvrmENSL94UL5SUdNcidKRNsmvVn9+qFy9YgyI= X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6095135)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(93006095)(93001095)(3002001)(10201501046)(6055026)(6096035)(20161123563025)(20161123561025)(201703131430075)(201703131433075)(201703131441075)(201703131448075)(201703161259150)(20161123565025)(20161123559100)(20161123556025)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CY4PR03MB2693;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(400006)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CY4PR03MB2693; X-Forefront-PRVS: 0444EB1997 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY4PR03MB2693;23:bquBpWF7IL+eNWe49Mr7q5Olo1y3QuvmXvemIOKk/?= =?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tRQ1kOz5TVd8+7CGuSHruslzlHYCKhPZoX9qRb6E4PZlsOWPrJd4gInC7l4Glr6YV9VL+hyS2BteGfMyT+2l7bFdqbc/jLuvIvsT6Poc0p+T+sCJfpfd4PjGz/J9/pZGU40iupXG0GfEcM0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2017 14:10:34.8830 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR03MB2693 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2555 Lines: 66 For some dpio functions, a cpu id parameter value of -1 is valid and means "any". But when trying to validate this param value against an upper limit, in this case num_possible_cpus(), we risk obtaining the wrong result due to an implicit cast. Avoid an incorrect check result by explicitly comparing the cpu id with the "any" value before verifying the upper bound. Signed-off-by: Ioana Radulescu --- v2: - make condition more clear (as suggested by Dan Carpenter) - don't use unlikely() drivers/staging/fsl-mc/bus/dpio/dpio-service.c | 4 ++-- drivers/staging/fsl-mc/include/dpaa2-io.h | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/staging/fsl-mc/bus/dpio/dpio-service.c b/drivers/staging/fsl-mc/bus/dpio/dpio-service.c index f809682..a609ec8 100644 --- a/drivers/staging/fsl-mc/bus/dpio/dpio-service.c +++ b/drivers/staging/fsl-mc/bus/dpio/dpio-service.c @@ -76,7 +76,7 @@ static inline struct dpaa2_io *service_select_by_cpu(struct dpaa2_io *d, if (d) return d; - if (unlikely(cpu >= num_possible_cpus())) + if (cpu != DPAA2_IO_ANY_CPU && cpu >= num_possible_cpus()) return NULL; /* @@ -121,7 +121,7 @@ struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc) return NULL; /* check if CPU is out of range (-1 means any cpu) */ - if (desc->cpu >= num_possible_cpus()) { + if (desc->cpu != DPAA2_IO_ANY_CPU && desc->cpu >= num_possible_cpus()) { kfree(obj); return NULL; } diff --git a/drivers/staging/fsl-mc/include/dpaa2-io.h b/drivers/staging/fsl-mc/include/dpaa2-io.h index c564609..afc2d06 100644 --- a/drivers/staging/fsl-mc/include/dpaa2-io.h +++ b/drivers/staging/fsl-mc/include/dpaa2-io.h @@ -54,6 +54,8 @@ struct device; * for dequeue. */ +#define DPAA2_IO_ANY_CPU -1 + /** * struct dpaa2_io_desc - The DPIO descriptor * @receives_notifications: Use notificaton mode. Non-zero if the DPIO @@ -91,8 +93,8 @@ irqreturn_t dpaa2_io_irq(struct dpaa2_io *obj); * @cb: The callback to be invoked when the notification arrives * @is_cdan: Zero for FQDAN, non-zero for CDAN * @id: FQID or channel ID, needed for rearm - * @desired_cpu: The cpu on which the notifications will show up. -1 means - * any CPU. + * @desired_cpu: The cpu on which the notifications will show up. Use + * DPAA2_IO_ANY_CPU if don't care * @dpio_id: The dpio index * @qman64: The 64-bit context value shows up in the FQDAN/CDAN. * @node: The list node -- 2.7.4