Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp60214ybt; Tue, 7 Jul 2020 16:04:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhmFoBR6EJPLrYYnaVCiJpKKGhTFQWhVoVLMJhi9BPhh/H3xkpd7TtoEEiBwy5WB15uQEv X-Received: by 2002:aa7:c50e:: with SMTP id o14mr64362197edq.168.1594163063606; Tue, 07 Jul 2020 16:04:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594163063; cv=none; d=google.com; s=arc-20160816; b=mavBIpyduXxGS4DpRFMKvOoqH5D+Xc+E3ByL6LfecQ2KjT8Hbhaw8QwTOQWmK8pPfL jJTEHcGk8j5+lNCn+pRxYeVvv1ymOb15YrcdcXodhrCh1hlZ+q/m8Eh5u9IYK7u7omvF hzBE/y3cvAkUHtyXU3n6yQyMIkCLeINAu3SfaIUvDDF0+RnTknqsEgpOmDgTd9N+p4cU m8YThnQfj5DuTksRu8qlAFSi6QucqRbtR+R3Gl/hJWdsCmskbsfzg2pwKESPE03E2txw Y/sxP59tWfpJWLJVmPPG7EeebJZlkvmOREvtNz63Ao2/EGc0HT8YfItxizvjobZANuMP hEYA== 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:message-id:date :subject:cc:to:from:dkim-signature; bh=eDBfMfO3gH5XivlUuml3iPrkilSX9rGahEiW/VBWUow=; b=GhRlAFe5nDVrEzl1qITOc/7AhLyfIrImKMbS6SiUuhH1zOR4ptYqPv8fdkoG9pyHuX RXS9WS4dIczZ7N8kM08Z3W/uPt2p3QZ2m0qk2ZzxXBpn0k4JBc66vFVLOL2e7r94JF28 Dh5L72mnOyPsR6MZdLI8Xs/KG6/c2QspTLhRrgcKuH0zrN8sIsUIsInQo1bhWhPshnf3 lVxoNqS6J6iB9LZ21T2VRmC5J18r471H4gg8bLB0rQTlhbND/e/cQ5x+flAlgc/bwkqK K0akSDq7q8OETiMLwtXbmn1RzrgtVFif/ObAgDvZKkbE6I92o4bg4tUlJ1M42VWgc4Pe 5Etw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ou7IvQjQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i5si15936709edn.258.2020.07.07.16.04.00; Tue, 07 Jul 2020 16:04:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ou7IvQjQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728885AbgGGXDr (ORCPT + 99 others); Tue, 7 Jul 2020 19:03:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728001AbgGGXDq (ORCPT ); Tue, 7 Jul 2020 19:03:46 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8158AC061755 for ; Tue, 7 Jul 2020 16:03:45 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id rk21so48455563ejb.2 for ; Tue, 07 Jul 2020 16:03:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=eDBfMfO3gH5XivlUuml3iPrkilSX9rGahEiW/VBWUow=; b=ou7IvQjQr1Q/ko6wXjR104fN8y9sz8sdtEUgt6XuwBDCe/bqL7yG4MquFqpwpesoNz 4mQHGHG8rhlYgMovXI+2u1t0kTuTb16vMzkYt8LMQfW8dsJ10uVdWhGj2npLhQjxTFQ5 bNEPjnVtwAwiDjhRcHBMX+CO15CDxvWI39OwhnkpSme+k+8If4V3geXKh7TC41tiqRIl LazOhFBwS0CWwj+s5WvoSbL8jtujUEJ+RcbWYSvwyTf6lWjOomxJWLNceHmM95FPgwtM XsFlIm8VWI6zmE4UL1ki6huTv6nhWYtsjREj2tovGbxGtnv8/GoAxXfc3MvlWf8VJDi/ YPCQ== 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; bh=eDBfMfO3gH5XivlUuml3iPrkilSX9rGahEiW/VBWUow=; b=oVQ/JZ0cXCPZudk6FzuqvBYNmZcKsp4aPkLe45grDEgrquyUYaRV4BQWZmYIQjstLU WTzMzbpu/DpI8IKrZ3W9yQ3HQ+9kjqkZ7xDCLDQbH4qWhmzzfI1wOYa7no9zduqPp73F tBulsRJPgrDMPCMbCxr+wdK+XDvh3iwoFjZdzHYwaoMWspK0ZacV722u8wknupRCwQwn 9YIzj93dlQ5+wCWJ28yUk3+nXm6ODh60VKGfVUQV/8hHtxTlUvAROWMtF4JEN8Flj1N1 Xtg/1Inn91f/V1L+fTYFbx8ZrSlM/WHpdHGFFJsIN0FMx4/tPtSbZrWriZXbq4b80aR0 wzFg== X-Gm-Message-State: AOAM533zh5VLBJ24qVLDLjO58MZsz+AtARF3eZcJ0xiWKQz24l9Z6mmX DEZfW0rl2PAgSmhwfpQwQpM= X-Received: by 2002:a17:906:f94c:: with SMTP id ld12mr48127036ejb.426.1594163024217; Tue, 07 Jul 2020 16:03:44 -0700 (PDT) Received: from net.saheed (54007186.dsl.pool.telekom.hu. [84.0.113.134]) by smtp.gmail.com with ESMTPSA id f10sm27096310edx.5.2020.07.07.16.03.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 16:03:43 -0700 (PDT) From: Saheed Olayemi Bolarinwa To: helgaas@kernel.org, Arnd Bergmann , Greg Kroah-Hartman Cc: Bolarinwa Olayemi Saheed , bjorn@helgaas.com, skhan@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/13] misc: rtsx: Check the return value of pcie_capability_read_*() Date: Wed, 8 Jul 2020 00:03:13 +0200 Message-Id: <20200707220324.8425-3-refactormyself@gmail.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20200707220324.8425-1-refactormyself@gmail.com> References: <20200707220324.8425-1-refactormyself@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bolarinwa Olayemi Saheed On failure pcie_capability_read_dword() sets it's last parameter, val to 0. In which case (val & PCI_EXP_DEVCTL2_LTR_EN) evaluates to 0. However, with Patch 13/13, it is possible that val is set to ~0 on failure. This would introduce a bug because (x & x) == (~0 & x). This bug can be avoided without changing the function's behaviour if the return value of pcie_capability_read_word is checked to confirm success. Check the return value of pcie_capability_read_word() to ensure success. Suggested-by: Bjorn Helgaas Signed-off-by: Bolarinwa Olayemi Saheed --- drivers/misc/cardreader/rts5227.c | 5 +++-- drivers/misc/cardreader/rts5249.c | 5 +++-- drivers/misc/cardreader/rts5260.c | 5 +++-- drivers/misc/cardreader/rts5261.c | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/misc/cardreader/rts5227.c b/drivers/misc/cardreader/rts5227.c index 3a9467aaa435..7a20a4898d07 100644 --- a/drivers/misc/cardreader/rts5227.c +++ b/drivers/misc/cardreader/rts5227.c @@ -92,6 +92,7 @@ static void rts5227_force_power_down(struct rtsx_pcr *pcr, u8 pm_state) static int rts5227_extra_init_hw(struct rtsx_pcr *pcr) { u16 cap; + int ret; rtsx_pci_init_cmd(pcr); @@ -105,8 +106,8 @@ static int rts5227_extra_init_hw(struct rtsx_pcr *pcr) /* LED shine disabled, set initial shine cycle period */ rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, OLT_LED_CTL, 0x0F, 0x02); /* Configure LTR */ - pcie_capability_read_word(pcr->pci, PCI_EXP_DEVCTL2, &cap); - if (cap & PCI_EXP_DEVCTL2_LTR_EN) + ret = pcie_capability_read_word(pcr->pci, PCI_EXP_DEVCTL2, &cap); + if (!ret && (cap & PCI_EXP_DEVCTL2_LTR_EN)) rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, LTR_CTL, 0xFF, 0xA3); /* Configure OBFF */ rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, OBFF_CFG, 0x03, 0x03); diff --git a/drivers/misc/cardreader/rts5249.c b/drivers/misc/cardreader/rts5249.c index 6c6c9e95a29f..2b05e8663431 100644 --- a/drivers/misc/cardreader/rts5249.c +++ b/drivers/misc/cardreader/rts5249.c @@ -95,6 +95,7 @@ static void rts5249_init_from_cfg(struct rtsx_pcr *pcr) { struct rtsx_cr_option *option = &(pcr->option); u32 lval; + int ret; if (CHK_PCI_PID(pcr, PID_524A)) rtsx_pci_read_config_dword(pcr, @@ -118,8 +119,8 @@ static void rts5249_init_from_cfg(struct rtsx_pcr *pcr) if (option->ltr_en) { u16 val; - pcie_capability_read_word(pcr->pci, PCI_EXP_DEVCTL2, &val); - if (val & PCI_EXP_DEVCTL2_LTR_EN) { + ret = pcie_capability_read_word(pcr->pci, PCI_EXP_DEVCTL2, &val); + if (!ret && (val & PCI_EXP_DEVCTL2_LTR_EN)) { option->ltr_enabled = true; option->ltr_active = true; rtsx_set_ltr_latency(pcr, option->ltr_active_latency); diff --git a/drivers/misc/cardreader/rts5260.c b/drivers/misc/cardreader/rts5260.c index 7a9dbb778e84..934aeaeebfaf 100644 --- a/drivers/misc/cardreader/rts5260.c +++ b/drivers/misc/cardreader/rts5260.c @@ -498,6 +498,7 @@ static void rts5260_init_from_cfg(struct rtsx_pcr *pcr) { struct rtsx_cr_option *option = &pcr->option; u32 lval; + int ret; rtsx_pci_read_config_dword(pcr, PCR_ASPM_SETTING_5260, &lval); @@ -518,8 +519,8 @@ static void rts5260_init_from_cfg(struct rtsx_pcr *pcr) if (option->ltr_en) { u16 val; - pcie_capability_read_word(pcr->pci, PCI_EXP_DEVCTL2, &val); - if (val & PCI_EXP_DEVCTL2_LTR_EN) { + ret = pcie_capability_read_word(pcr->pci, PCI_EXP_DEVCTL2, &val); + if (!ret && (val & PCI_EXP_DEVCTL2_LTR_EN)) { option->ltr_enabled = true; option->ltr_active = true; rtsx_set_ltr_latency(pcr, option->ltr_active_latency); diff --git a/drivers/misc/cardreader/rts5261.c b/drivers/misc/cardreader/rts5261.c index 195822ec858e..2b6f61696e19 100644 --- a/drivers/misc/cardreader/rts5261.c +++ b/drivers/misc/cardreader/rts5261.c @@ -438,9 +438,10 @@ static void rts5261_init_from_cfg(struct rtsx_pcr *pcr) rtsx_pci_write_register(pcr, ASPM_FORCE_CTL, 0xFF, 0); if (option->ltr_en) { u16 val; + int ret; - pcie_capability_read_word(pcr->pci, PCI_EXP_DEVCTL2, &val); - if (val & PCI_EXP_DEVCTL2_LTR_EN) { + ret = pcie_capability_read_word(pcr->pci, PCI_EXP_DEVCTL2, &val); + if (!ret && (val & PCI_EXP_DEVCTL2_LTR_EN)) { option->ltr_enabled = true; option->ltr_active = true; rtsx_set_ltr_latency(pcr, option->ltr_active_latency); -- 2.18.2