Skip to content

Commit 3b99355

Browse files
RengarajanSSkuba-moo
authored andcommitted
net: lan743x: Modify the EEPROM and OTP size for PCI1xxxx devices
Maximum OTP and EEPROM size for hearthstone PCI1xxxx devices are 8 Kb and 64 Kb respectively. Adjust max size definitions and return correct EEPROM length based on device. Also prevent out-of-bound read/write. Signed-off-by: Rengarajan S <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 7a91722 commit 3b99355

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

drivers/net/ethernet/microchip/lan743x_ethtool.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#define EEPROM_MAC_OFFSET (0x01)
1919
#define MAX_EEPROM_SIZE (512)
2020
#define MAX_OTP_SIZE (1024)
21+
#define MAX_HS_OTP_SIZE (8 * 1024)
22+
#define MAX_HS_EEPROM_SIZE (64 * 1024)
2123
#define OTP_INDICATOR_1 (0xF3)
2224
#define OTP_INDICATOR_2 (0xF7)
2325

@@ -272,6 +274,9 @@ static int lan743x_hs_otp_read(struct lan743x_adapter *adapter, u32 offset,
272274
int ret;
273275
int i;
274276

277+
if (offset + length > MAX_HS_OTP_SIZE)
278+
return -EINVAL;
279+
275280
ret = lan743x_hs_syslock_acquire(adapter, LOCK_TIMEOUT_MAX_CNT);
276281
if (ret < 0)
277282
return ret;
@@ -320,6 +325,9 @@ static int lan743x_hs_otp_write(struct lan743x_adapter *adapter, u32 offset,
320325
int ret;
321326
int i;
322327

328+
if (offset + length > MAX_HS_OTP_SIZE)
329+
return -EINVAL;
330+
323331
ret = lan743x_hs_syslock_acquire(adapter, LOCK_TIMEOUT_MAX_CNT);
324332
if (ret < 0)
325333
return ret;
@@ -497,6 +505,9 @@ static int lan743x_hs_eeprom_read(struct lan743x_adapter *adapter,
497505
u32 val;
498506
int i;
499507

508+
if (offset + length > MAX_HS_EEPROM_SIZE)
509+
return -EINVAL;
510+
500511
retval = lan743x_hs_syslock_acquire(adapter, LOCK_TIMEOUT_MAX_CNT);
501512
if (retval < 0)
502513
return retval;
@@ -539,6 +550,9 @@ static int lan743x_hs_eeprom_write(struct lan743x_adapter *adapter,
539550
u32 val;
540551
int i;
541552

553+
if (offset + length > MAX_HS_EEPROM_SIZE)
554+
return -EINVAL;
555+
542556
retval = lan743x_hs_syslock_acquire(adapter, LOCK_TIMEOUT_MAX_CNT);
543557
if (retval < 0)
544558
return retval;
@@ -604,9 +618,9 @@ static int lan743x_ethtool_get_eeprom_len(struct net_device *netdev)
604618
struct lan743x_adapter *adapter = netdev_priv(netdev);
605619

606620
if (adapter->flags & LAN743X_ADAPTER_FLAG_OTP)
607-
return MAX_OTP_SIZE;
621+
return adapter->is_pci11x1x ? MAX_HS_OTP_SIZE : MAX_OTP_SIZE;
608622

609-
return MAX_EEPROM_SIZE;
623+
return adapter->is_pci11x1x ? MAX_HS_EEPROM_SIZE : MAX_EEPROM_SIZE;
610624
}
611625

612626
static int lan743x_ethtool_get_eeprom(struct net_device *netdev,

0 commit comments

Comments
 (0)