Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp4563881pja; Thu, 21 Nov 2019 21:57:20 -0800 (PST) X-Google-Smtp-Source: APXvYqwS71rBPNPlVa8Nrm9iBpFlRj5ywBr6s3qS5GfVxWaSLqrd4jjxGFWxKAejBqA7R5mhNtVj X-Received: by 2002:a17:906:3602:: with SMTP id q2mr19930407ejb.167.1574402240203; Thu, 21 Nov 2019 21:57:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574402240; cv=none; d=google.com; s=arc-20160816; b=x85LH1roJl9ZrC0WPPjbMa+iPQd1c9/dOnUmaFcdFv9RhC4HMi7dfRmRwyITyq+d3z qmjfNyKMECX5RjNMEhmDU1PXPOtVEXCS8NjmJ0iYTVZiJ2YukSHXWm1cc19fIeUjZQNu rMszKI3STybN7/mLj/Fwvu3qdwFN+NvNx7mh6hgIUg4W7jx9nTygTnyCvp/CFXfn++gj 1H0DOXuvT4HSefHxSTMayGYKKJU+RWxRLBomjxExrsYuwvmTDg7KXcJdEIvxAmWpRp/N 3gbX5CBe6vVeu9tysM9E51R0ZbqTUhGDvf0iPBjuf7yQycezTBSqRJauPdBXpLE6BBNP mV+w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TDzgNA6oACHUyF+M7fHbJXq5Tp55CDvvGrwo4NyAnTQ=; b=VRSqWS5RQe6xz7N8E0d+aKFiVzN/7ziRO1WcOGyqHc12N45i8tIYkdXlMPf0NjhGhB u25apsz49MEBnaAMozT6ybRc9TG4hUOFOq4GNyG0F5xq+uS8TA1HE3u4CGKiOGymkWMl drSwtBSayOppFd1qip3itMYMNUluxhVz1//Ca5BRihMgZo+q5ACNlxYMTVtErRcpefKo V0mx046UZBF1P52nTJOGv/ja9WHAcSfSCOTqqYg5wEtDydT8isUkvtf7AD6BgKLJON6T F4ZaGp/vw34lBurIypBY7mzU7t3ORRX9wt/SmSaj0VhvA4TNlDyhbi8dPFhYiuQRftrW jHjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1paX5aYw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12si3492674eje.253.2019.11.21.21.56.55; Thu, 21 Nov 2019 21:57:20 -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=1paX5aYw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726881AbfKVFwp (ORCPT + 99 others); Fri, 22 Nov 2019 00:52:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:58360 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728589AbfKVFwg (ORCPT ); Fri, 22 Nov 2019 00:52:36 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 249D32068F; Fri, 22 Nov 2019 05:52:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574401954; bh=1RMGphbcr6JtM+J9UMC6O9MEbcjofAiElGx6HGAXfr0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1paX5aYw8d83v/Ie2I9nuJP9YhX42aUwkZPMVBM8AJK6YY8OC/0558kdmLeD8H6OP AgQMU+xYNueETh3BF+0IseKLiHbpkXX8e1wb7S7LBgjpsmA0mA6wPDFmt3EpdZ06tK lxEK5UXbwGAI0QOZhcKyApA89RCCjYLv/z64Rlz4= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Edward Cree , "David S . Miller" , Sasha Levin , netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 177/219] sfc: suppress duplicate nvmem partition types in efx_ef10_mtd_probe Date: Fri, 22 Nov 2019 00:48:29 -0500 Message-Id: <20191122054911.1750-170-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122054911.1750-1-sashal@kernel.org> References: <20191122054911.1750-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 7eeac3d6cfe89..a497aace7e4f4 100644 --- a/drivers/net/ethernet/sfc/ef10.c +++ b/drivers/net/ethernet/sfc/ef10.c @@ -6042,22 +6042,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; } @@ -6070,6 +6073,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); @@ -6098,6 +6108,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; @@ -6126,11 +6137,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