Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp2599660ybg; Fri, 31 Jul 2020 05:05:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgK7btSWDATsaB43JdH8YNZwlX7WgKsrMRHT7ta3hnnwSxzV+9SIXCdHFxM+wJSxzqsOqZ X-Received: by 2002:a17:906:c143:: with SMTP id dp3mr3689144ejc.504.1596197149159; Fri, 31 Jul 2020 05:05:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596197149; cv=none; d=google.com; s=arc-20160816; b=pPHfm6/Sz1Uuaf2gngTw3CVGerh7xeFr5WQTJn7xu7N+m0j0aJzXC1rgq+6yU+n81b lYO1tpEtPZ4Tmwwbl4yjzICNyjX0xip5c1uBlbuxm13F00FQsfPuDwsqaaMORh4nF46x y2XeJEZ2mlLCxxEfPBFEZD57wXntdwhsHelOMd8LV1OGTpwI+QEpWn1XoRq8bApGRvEM AlOv68it78+Zinz0Tu5N3Mwb6NOdr3+8KW+NeqPvRQTh8oIiYesBCJDW0Dn6rEPtP0uj K35qorsO0O0QpGv43ZGYSkvr7bZW/nhvjZcwfpXwANFJBt2XvwYmiYDm0NfQkadcyuGW xlPg== 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=ml221r4dHqXe07i3xfLOyBkeN0U7ADgIKojP7DQw/XU=; b=LW0HemYyP+ZpVu89umg1FCHhYM+JPcaKHAMQ7/MKIP2tAEGlkvB4FBx8ul1pnvV/gk aduHqR2xY2dh5lwL58DH0AwG0969y3nB8xOCJdy70uO9s2dWb+MT1xuxTGVL+Ffe5Zjw 6GKqa8bFXsyTgEBXJD+hjQcb+Ebs0ULTR7nOgcuI6WEK/KcNlHD6BU73ujh57o2/IjIR GvdWyPudTgOxVqJWUc52mOn05avjdR/bnk+DjeSLJyNo2kBQ8JNqyAqx4eewO1s/mzp4 2r43dFV7JEh+PqRYL83+8iGIDXlyIEb+TnDQjxzai8BzDsRHHEjFB328Gf0/Xcl6LJ+h bE9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tdc87K9U; 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 y16si5116107edu.65.2020.07.31.05.05.26; Fri, 31 Jul 2020 05:05:49 -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=tdc87K9U; 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 S1733076AbgGaMCw (ORCPT + 99 others); Fri, 31 Jul 2020 08:02:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733001AbgGaMCV (ORCPT ); Fri, 31 Jul 2020 08:02:21 -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 05544C061574; Fri, 31 Jul 2020 05:02:21 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id bo3so8536415ejb.11; Fri, 31 Jul 2020 05:02:20 -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=ml221r4dHqXe07i3xfLOyBkeN0U7ADgIKojP7DQw/XU=; b=tdc87K9UnCJy6h8rTMzof2JLZE4gpUzsMej7iiUfVOUd8Id5xNJOXDAFSfsuz1w6u7 iPtFsNJnx1SkMUgFfvLUPtv9cu83vKOHYyRXtSmX7KgJcVnPQ3gnhE8Vn7frgHaIxoVi Z+sknEjd13Z6IBnP0Jr1Gxd6tF5MYqxOo+hJMYp26pN1GTyaYHyecoyhHHtGfC0VobdR mBKxZ07cIazEDKChb+I7ckeC2rc+uHvtBAkpedhjsjR469MF4Evszk9aoUuX/w/fp92p VaLu2ghSiNVcmXKdZDtlEE5Eunx6Vqus4obfwNnNzChqQ/gvK3jUU6SEn0bMJjdZoz9a s00A== 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=ml221r4dHqXe07i3xfLOyBkeN0U7ADgIKojP7DQw/XU=; b=VO/ZHz++ggkO+pZzm9eTS5b2vfxdGXT75PU0zHBT5WIBFppuBmqUp8V9qnlTQI/VVJ nv7PJUUQeEzZsET6ZeSiK7uiP14M+ggjfBA0y7yqEnkT9CqavTltXov8uzwQGaPEeF2N UqS1q5e7iL6Z3H69POQO0esEl54ZQKeRafBIn6Sg8RLu/9r6gYv/nZle4vJWdHUgbQCP BJvJbEIIjMqTBerXA3Zvit58XF9LGFvMezdg/Cqc6Ar1N9wwbzs6sKeNxbob/USMMF/5 c31nvKEV85k2QHUptBkyRJzFzXoy6TJqrOxkX26fdDB4eiBsHslvBSs0aGMj+aDVk0s5 cs8Q== X-Gm-Message-State: AOAM533jhp02Z7kl5ZeUzfHPAv465O7ZvSo0NDgiHpFKKKRWtKAazGcq EiD1y+0AVRUV25hdIZrueB+a7UDtjUwS2g== X-Received: by 2002:a17:906:a94b:: with SMTP id hh11mr3659252ejb.104.1596196939763; Fri, 31 Jul 2020 05:02:19 -0700 (PDT) Received: from net.saheed (95C84E0A.dsl.pool.telekom.hu. [149.200.78.10]) by smtp.gmail.com with ESMTPSA id j5sm9091734ejk.87.2020.07.31.05.02.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 05:02:19 -0700 (PDT) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org, Arnd Bergmann , Greg Kroah-Hartman Cc: "Saheed O. Bolarinwa" , bjorn@helgaas.com, skhan@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 02/12] misc: rtsx: Check if pcie_capability_read_*() reads ~0 Date: Fri, 31 Jul 2020 13:02:30 +0200 Message-Id: <20200731110240.98326-3-refactormyself@gmail.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20200731110240.98326-1-refactormyself@gmail.com> References: <20200731110240.98326-1-refactormyself@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On failure pcie_capability_read_word() sets it's last parameter, val to 0. In which case (val & PCI_EXP_DEVCTL2_LTR_EN) evaluates to 0. However, with Patch 12/12, it is possible that val is set to ~0 on failure. This would introduce a bug because (x & x) == (~0 & x). Since ~0 is an invalid value here, Add an extra check for ~0 to the if condition to ensure success. Suggested-by: Bjorn Helgaas Signed-off-by: Saheed O. Bolarinwa --- drivers/misc/cardreader/rts5227.c | 2 +- drivers/misc/cardreader/rts5249.c | 2 +- drivers/misc/cardreader/rts5260.c | 2 +- drivers/misc/cardreader/rts5261.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/misc/cardreader/rts5227.c b/drivers/misc/cardreader/rts5227.c index 3a9467aaa435..cab816639df1 100644 --- a/drivers/misc/cardreader/rts5227.c +++ b/drivers/misc/cardreader/rts5227.c @@ -106,7 +106,7 @@ static int rts5227_extra_init_hw(struct rtsx_pcr *pcr) 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) + if ((cap != (u16)~0) && (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..4382ac753fda 100644 --- a/drivers/misc/cardreader/rts5249.c +++ b/drivers/misc/cardreader/rts5249.c @@ -119,7 +119,7 @@ static void rts5249_init_from_cfg(struct rtsx_pcr *pcr) u16 val; pcie_capability_read_word(pcr->pci, PCI_EXP_DEVCTL2, &val); - if (val & PCI_EXP_DEVCTL2_LTR_EN) { + if ((val != (u16)~0) && (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..3d52c86aaaa3 100644 --- a/drivers/misc/cardreader/rts5260.c +++ b/drivers/misc/cardreader/rts5260.c @@ -519,7 +519,7 @@ static void rts5260_init_from_cfg(struct rtsx_pcr *pcr) u16 val; pcie_capability_read_word(pcr->pci, PCI_EXP_DEVCTL2, &val); - if (val & PCI_EXP_DEVCTL2_LTR_EN) { + if ((val != (u16)~0) && (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..7e1188740194 100644 --- a/drivers/misc/cardreader/rts5261.c +++ b/drivers/misc/cardreader/rts5261.c @@ -440,7 +440,7 @@ static void rts5261_init_from_cfg(struct rtsx_pcr *pcr) u16 val; pcie_capability_read_word(pcr->pci, PCI_EXP_DEVCTL2, &val); - if (val & PCI_EXP_DEVCTL2_LTR_EN) { + if ((val != (u16)~0) && (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.4