Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp2693967pxy; Mon, 3 May 2021 06:06:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzI+6q8ZvzdH0TA+wR6mY7+M3DaokboSaZIcMV/iSc3enmvKplEwiMvS481hxPGb89zX+UG X-Received: by 2002:a63:5245:: with SMTP id s5mr18476624pgl.234.1620047201027; Mon, 03 May 2021 06:06:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620047201; cv=none; d=google.com; s=arc-20160816; b=Wc+6QePWijTWKfbkguDPJfIRxJdESpruFSanEyrpX9qOZu9ylJzqgQa+WA7TTC9iGN eRWnF0rG2WDzppc9LvNAJmXIYW7dmmNc2fZeeo65cTRukX3Op5l0Jz/6uyBVaMsiIXq4 5VkYBHSnCjU+z4PMPpx4mA1zYbt6XG+vhKDh/Uc/nAbijp9aUS7S/6frXqFtjLb19Gda c12c/jwLPuT31JUeD12Af5BTPxnKRDZp7s00RznbkozaEZxUEW0l7KZsS4kusJr8yE9s nIeE8xL4BOXdF8vqKlQgYb6Uv8BsddWrfiqkGayEQIgJfJIkTI2nY4GVHJ3iAiDdi/3Q /X+A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eJWhPskxYiKiM2NMnW3xkknIqkBGtXoHrTTt5g/tW9k=; b=liSoLgZYhxyKe+m4MR9meMkk4EzJSZWNnIoeUPAFpLYcK2ECPTB27EzPhzv9cXQATT D+Nz0/KSlA8uy42wfkyoM2hRm0Yj+GT3oj72fD205Rchup+J99bHsKBs0qa21nKSXgYd TNTz5v710hmas6KpaOoY8oXLRd46eqUhn+o9TPnTk32gww+jbXVlcXmg677hSE6OxpxP uNn1y3Aqi20Drm7iHI+ZhBKFPIFVNMW1INvuhTLzPToiYLrFJ+SChyCY++4wrIumvte6 OerTWvbCjGHNiDTva4y9w+Yd2uqTLTR7dVYGhFCKrw1ZnoYUec5xlbo1UmnVtXxPDHhf zT1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QZR+rAkQ; 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 x9si9728290pgp.117.2021.05.03.06.06.21; Mon, 03 May 2021 06:06:41 -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=QZR+rAkQ; 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 S233746AbhECMAh (ORCPT + 99 others); Mon, 3 May 2021 08:00:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:34466 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233527AbhECMAU (ORCPT ); Mon, 3 May 2021 08:00:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 55CB76127A; Mon, 3 May 2021 11:59:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620043166; bh=iB+97Pz4ESnaMRp2W+AYh/9PT653VTU0bZ+ASzxl26c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QZR+rAkQfHLusGUytZbu6T2EjtG/ZFkhz3qZx6Sl3BgY63ANObQuNiT47L9/IZSjn LUHjIrUIcX51DQUS/TS8/FyGaHMImOvcwcgtmxkZcJWcRdPpvnpfhyJ2dTUNCGoxm/ 7MAoKyz33W6m0cHPTEPlgpNIVAx6zbhdrCR3xC94= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Du Cheng , Shannon Nelson , "David S . Miller" , stable , Greg Kroah-Hartman Subject: [PATCH 23/69] ethernet: sun: niu: fix missing checks of niu_pci_eeprom_read() Date: Mon, 3 May 2021 13:56:50 +0200 Message-Id: <20210503115736.2104747-24-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210503115736.2104747-1-gregkh@linuxfoundation.org> References: <20210503115736.2104747-1-gregkh@linuxfoundation.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Du Cheng 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 Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/sun/niu.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/sun/niu.c b/drivers/net/ethernet/sun/niu.c index d70cdea756d1..74e748662ec0 100644 --- a/drivers/net/ethernet/sun/niu.c +++ b/drivers/net/ethernet/sun/niu.c @@ -8097,6 +8097,8 @@ static int niu_pci_vpd_scan_props(struct niu *np, u32 start, u32 end) 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; @@ -8141,8 +8143,12 @@ static int niu_pci_vpd_scan_props(struct niu *np, u32 start, u32 end) 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; @@ -8152,14 +8158,14 @@ static int niu_pci_vpd_scan_props(struct niu *np, u32 start, u32 end) } /* 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; @@ -8168,12 +8174,14 @@ static void niu_pci_vpd_fetch(struct niu *np, u32 start) 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; @@ -8181,9 +8189,12 @@ static void niu_pci_vpd_fetch(struct niu *np, u32 start) 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 */ @@ -9274,8 +9285,11 @@ static int niu_get_invariants(struct niu *np) 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) { -- 2.31.1