Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3525722pxj; Mon, 24 May 2021 08:39:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxXWyrwbhK2pfHbKI8xGx2e/M5qwtl1Fo3D2ABCv3kPDT/IwomJ9rQGcH29x1CFAtkXtkV X-Received: by 2002:a17:906:368e:: with SMTP id a14mr23808793ejc.366.1621870774379; Mon, 24 May 2021 08:39:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621870774; cv=none; d=google.com; s=arc-20160816; b=VyWh9TAVxcp7OOYgHw+vuzfiPglwWXZKnBnVMxRPN6tT2+sK5Iv6vrRUvw87JjnAEe Sc9b+zcMdDRDQ4Yd1YVbBx6nrAGnx6XG6yyREQWilYBB5bhmDgnsg+SYVGprViops43O ZgQTzT7bkO2WaBih9pf7gHCvyFzF4zV1w0kW2iTSdtSRvvsFZBq9dczgo8UELt66bitD C8t/vPSt1cXCcn8BvA5r0kHP/iOBUbHKzweHHQwWVKAWSDLlh6sU04z2eSdYWik0Bxud Fh3uXlm7R8im37rU7H3MK35NPavRtFnU5yuHVT+a1Pl2bvt5wqBk4ghmP6GEtClwwQ38 wCrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Qqbyca4iCFIExr4ho/enaIJesrJzQ0R5c7fkkMYQRiQ=; b=1ARt8OZprNdPGdxo1hPkA8wBoV1WFBYiIu4wo6H6U2ppwCPRpvZfYg01KdgaxavP2w QfTO7nOm70v2TRnxmtBiakC/wr6qo9a3z+sfv2+aSZ7M7eIg3ylrv4Ga9v5H/snUNhIE o94vfzbxzngxTHrTRvK7gYLdHvQ026mvIaoi3JH6dR13/fNynEm1SzTIg8/jInFGeYTI RBPbf49bOa1xv6muX+UNx+ACuxeDoV/47LL94kaZfp0fZij4rc5D9wA4LaFZobvnPItV PO+nbp3zZa6Dw6kgq0NOC0kpFwBYwJG85qm/4zXpXV4PB89JPcAyEox8N+RtmpMAxTjc 7ang== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jpyebvsE; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id le4si12576277ejc.650.2021.05.24.08.39.09; Mon, 24 May 2021 08:39:34 -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=@linuxfoundation.org header.s=korg header.b=jpyebvsE; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234461AbhEXPji (ORCPT + 99 others); Mon, 24 May 2021 11:39:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:50520 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233963AbhEXPgl (ORCPT ); Mon, 24 May 2021 11:36:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 80A7E61416; Mon, 24 May 2021 15:32:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621870373; bh=Wcu1d9Mug0WrHSlaZvr6VdvPqy1pPkbAFqQgwV4UK3E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jpyebvsEJ8q4TWLVbdA9ECAmoT5EiPAdSfukBDhZ9W1CX1c04Izo1JqGOF8juoPzk MnvMnbyPbp9o6Dui3hgA4bF3jY5L4/cKostZnOC5YfQ8dA0RH0VLArAz5GBdWnRV/h sl3sGqsZZTUy8lh6Uwj9hFSz103sbw8FF95j6Vd0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Du Cheng , Shannon Nelson , "David S. Miller" Subject: [PATCH 4.9 27/36] ethernet: sun: niu: fix missing checks of niu_pci_eeprom_read() Date: Mon, 24 May 2021 17:25:12 +0200 Message-Id: <20210524152325.040063431@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152324.158146731@linuxfoundation.org> References: <20210524152324.158146731@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Du Cheng commit e6e337708c22f80824b82d4af645f20715730ad0 upstream. niu_pci_eeprom_read() may fail, so add checks to its return value and propagate the error up the callstack. An examination of the callstack up to niu_pci_eeprom_read shows that: niu_pci_eeprom_read() // returns int niu_pci_vpd_scan_props() // returns int niu_pci_vpd_fetch() // returns *void* niu_get_invariants() // returns int since niu_pci_vpd_fetch() returns void which breaks the bubbling up, change its return type to int so that error is propagated upwards. Signed-off-by: Du Cheng Cc: Shannon Nelson Cc: David S. Miller Cc: stable Link: https://lore.kernel.org/r/20210503115736.2104747-24-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/sun/niu.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) --- a/drivers/net/ethernet/sun/niu.c +++ b/drivers/net/ethernet/sun/niu.c @@ -8119,6 +8119,8 @@ static int niu_pci_vpd_scan_props(struct start += 3; prop_len = niu_pci_eeprom_read(np, start + 4); + if (prop_len < 0) + return prop_len; err = niu_pci_vpd_get_propname(np, start + 5, namebuf, 64); if (err < 0) return err; @@ -8163,8 +8165,12 @@ static int niu_pci_vpd_scan_props(struct netif_printk(np, probe, KERN_DEBUG, np->dev, "VPD_SCAN: Reading in property [%s] len[%d]\n", namebuf, prop_len); - for (i = 0; i < prop_len; i++) - *prop_buf++ = niu_pci_eeprom_read(np, off + i); + for (i = 0; i < prop_len; i++) { + err = niu_pci_eeprom_read(np, off + i); + if (err < 0) + return err; + *prop_buf++ = err; + } } start += len; @@ -8174,14 +8180,14 @@ static int niu_pci_vpd_scan_props(struct } /* ESPC_PIO_EN_ENABLE must be set */ -static void niu_pci_vpd_fetch(struct niu *np, u32 start) +static int niu_pci_vpd_fetch(struct niu *np, u32 start) { u32 offset; int err; err = niu_pci_eeprom_read16_swp(np, start + 1); if (err < 0) - return; + return err; offset = err + 3; @@ -8190,12 +8196,14 @@ static void niu_pci_vpd_fetch(struct niu u32 end; err = niu_pci_eeprom_read(np, here); + if (err < 0) + return err; if (err != 0x90) - return; + return -EINVAL; err = niu_pci_eeprom_read16_swp(np, here + 1); if (err < 0) - return; + return err; here = start + offset + 3; end = start + offset + err; @@ -8203,9 +8211,12 @@ static void niu_pci_vpd_fetch(struct niu offset += err; err = niu_pci_vpd_scan_props(np, here, end); - if (err < 0 || err == 1) - return; + if (err < 0) + return err; + if (err == 1) + return -EINVAL; } + return 0; } /* ESPC_PIO_EN_ENABLE must be set */ @@ -9298,8 +9309,11 @@ static int niu_get_invariants(struct niu offset = niu_pci_vpd_offset(np); netif_printk(np, probe, KERN_DEBUG, np->dev, "%s() VPD offset [%08x]\n", __func__, offset); - if (offset) - niu_pci_vpd_fetch(np, offset); + if (offset) { + err = niu_pci_vpd_fetch(np, offset); + if (err < 0) + return err; + } nw64(ESPC_PIO_EN, 0); if (np->flags & NIU_FLAGS_VPD_VALID) {