Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp760661ybl; Wed, 4 Dec 2019 10:23:53 -0800 (PST) X-Google-Smtp-Source: APXvYqxD+Zl8YGRIOSugAZvG7A/TuK/GC6vD0HAskm9ztcEo+QPPxQkT8pe1v3okPgCxuObNOkiw X-Received: by 2002:aca:c38c:: with SMTP id t134mr3635419oif.175.1575483833285; Wed, 04 Dec 2019 10:23:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575483833; cv=none; d=google.com; s=arc-20160816; b=wFnLMCxRhwamiCKinAH1avS8tqAE6on4oz8LrAgEUn7vY3huwNdXWPW1KklndGO6Bz F1yIQZUFU3rjydTiTZaeiLAsoxzNJSJIgOVrLNGeTkC/R/HbOgXkviWhEX3VtnRRG8hF IjR7s7/HOuSL1VrtsVTYiTAWwr8dngULRGQgrsSLPHwPutZmjvN4pdMijpUM5vtq3cEj 9VrLK0hk+TWi1k1sCZlyjN2X1thV4i+d0mmZWk4gw7s2kCWm1jiH6++MOgNh8yejP4DK Z8OU/SMLRGanHHNwxL+OJY0rJHtl0jYUjuEHS8Ts3uENnlErg8v6DAN55BaJ61IbMqw+ WXTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sF0SXwjXrt0YiEg1tPweb0ZM6sJGO7cMG7hsG0vuox4=; b=EfVAoW+3vISsZoAKiG5P1Q5QCeWfN4Iepd/+tjTO4d31cKUmEcJRcThhJ9zax2qqL5 tZZED/wWGMnWniPKiet/sC4LI83PC2OYZEBAOOcd6eABbUG+Hk3hiA5MxKPlZ4tKNuBB WP8eEwHdkXFcEy7s4Lb1xMiLCz/pwkUYus35bcMNwJ/lzwbIhsic0WX3FVhWYRcc3Laq 4bVMxjXIOh6i+1wd8EqM60KJfntqufYFrJwO88amp/fy1qGmgKB+eaquPeiE38sRtXDT pDw9NlQSUqsul1mEdX8uH7YfVbylm4XhYc8FwT9Z8XlZodUf9pTMBYn1bXxJ9AMh/k9Q l9FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aBf5tdml; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w5si3651516oia.239.2019.12.04.10.23.41; Wed, 04 Dec 2019 10:23:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aBf5tdml; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730296AbfLDSVd (ORCPT + 99 others); Wed, 4 Dec 2019 13:21:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:54958 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729634AbfLDSGb (ORCPT ); Wed, 4 Dec 2019 13:06:31 -0500 Received: from localhost (unknown [217.68.49.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F3DE7206DF; Wed, 4 Dec 2019 18:06:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575482790; bh=sRG+9fKCS3DXqU/Po1FFA9lconLe0eam9JEYAbnx8JU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aBf5tdmlj5jlc4DyW98xGhOSi4G9ptFrRMR5D+7spj2yJpfUPxbCC0A5TtYBc0tyh Gnb3wc0ye3hsx1baIoHR6VzBwNxjtFnL6t/6JIr/qK0E9bXIYZpzpxcfnVu+uFNh+3 cVJ3TaJQS1Z8uJPV1h3jSC/L5cJ9h4QjmO8/g6s8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Edward Cree , "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 133/209] sfc: suppress duplicate nvmem partition types in efx_ef10_mtd_probe Date: Wed, 4 Dec 2019 18:55:45 +0100 Message-Id: <20191204175332.357016852@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204175321.609072813@linuxfoundation.org> References: <20191204175321.609072813@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Edward Cree [ Upstream commit 3366463513f544c12c6b88c13da4462ee9e7a1a1 ] Use a bitmap to keep track of which partition types we've already seen; for duplicates, return -EEXIST from efx_ef10_mtd_probe_partition() and thus skip adding that partition. Duplicate partitions occur because of the A/B backup scheme used by newer sfc NICs. Prior to this patch they cause sysfs_warn_dup errors because they have the same name, causing us not to expose any MTDs at all. Signed-off-by: Edward Cree Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/sfc/ef10.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/sfc/ef10.c b/drivers/net/ethernet/sfc/ef10.c index 09352ee43b55c..cc3be94d05622 100644 --- a/drivers/net/ethernet/sfc/ef10.c +++ b/drivers/net/ethernet/sfc/ef10.c @@ -5852,22 +5852,25 @@ static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = { { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" }, { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" }, }; +#define EF10_NVRAM_PARTITION_COUNT ARRAY_SIZE(efx_ef10_nvram_types) static int efx_ef10_mtd_probe_partition(struct efx_nic *efx, struct efx_mcdi_mtd_partition *part, - unsigned int type) + unsigned int type, + unsigned long *found) { MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN); MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX); const struct efx_ef10_nvram_type_info *info; size_t size, erase_size, outlen; + int type_idx = 0; bool protected; int rc; - for (info = efx_ef10_nvram_types; ; info++) { - if (info == - efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types)) + for (type_idx = 0; ; type_idx++) { + if (type_idx == EF10_NVRAM_PARTITION_COUNT) return -ENODEV; + info = efx_ef10_nvram_types + type_idx; if ((type & ~info->type_mask) == info->type) break; } @@ -5880,6 +5883,13 @@ static int efx_ef10_mtd_probe_partition(struct efx_nic *efx, if (protected) return -ENODEV; /* hide it */ + /* If we've already exposed a partition of this type, hide this + * duplicate. All operations on MTDs are keyed by the type anyway, + * so we can't act on the duplicate. + */ + if (__test_and_set_bit(type_idx, found)) + return -EEXIST; + part->nvram_type = type; MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type); @@ -5908,6 +5918,7 @@ static int efx_ef10_mtd_probe_partition(struct efx_nic *efx, static int efx_ef10_mtd_probe(struct efx_nic *efx) { MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX); + DECLARE_BITMAP(found, EF10_NVRAM_PARTITION_COUNT); struct efx_mcdi_mtd_partition *parts; size_t outlen, n_parts_total, i, n_parts; unsigned int type; @@ -5936,11 +5947,13 @@ static int efx_ef10_mtd_probe(struct efx_nic *efx) for (i = 0; i < n_parts_total; i++) { type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID, i); - rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type); - if (rc == 0) - n_parts++; - else if (rc != -ENODEV) + rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type, + found); + if (rc == -EEXIST || rc == -ENODEV) + continue; + if (rc) goto fail; + n_parts++; } rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts)); -- 2.20.1