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 <rengarajan.s@microchip.com> Link: https://patch.msgid.link/20250523173326.18509-1-rengarajan.s@microchip.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
7a91722e0d
commit
3b9935586a
|
@ -18,6 +18,8 @@
|
|||
#define EEPROM_MAC_OFFSET (0x01)
|
||||
#define MAX_EEPROM_SIZE (512)
|
||||
#define MAX_OTP_SIZE (1024)
|
||||
#define MAX_HS_OTP_SIZE (8 * 1024)
|
||||
#define MAX_HS_EEPROM_SIZE (64 * 1024)
|
||||
#define OTP_INDICATOR_1 (0xF3)
|
||||
#define OTP_INDICATOR_2 (0xF7)
|
||||
|
||||
|
@ -272,6 +274,9 @@ static int lan743x_hs_otp_read(struct lan743x_adapter *adapter, u32 offset,
|
|||
int ret;
|
||||
int i;
|
||||
|
||||
if (offset + length > MAX_HS_OTP_SIZE)
|
||||
return -EINVAL;
|
||||
|
||||
ret = lan743x_hs_syslock_acquire(adapter, LOCK_TIMEOUT_MAX_CNT);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
@ -320,6 +325,9 @@ static int lan743x_hs_otp_write(struct lan743x_adapter *adapter, u32 offset,
|
|||
int ret;
|
||||
int i;
|
||||
|
||||
if (offset + length > MAX_HS_OTP_SIZE)
|
||||
return -EINVAL;
|
||||
|
||||
ret = lan743x_hs_syslock_acquire(adapter, LOCK_TIMEOUT_MAX_CNT);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
@ -497,6 +505,9 @@ static int lan743x_hs_eeprom_read(struct lan743x_adapter *adapter,
|
|||
u32 val;
|
||||
int i;
|
||||
|
||||
if (offset + length > MAX_HS_EEPROM_SIZE)
|
||||
return -EINVAL;
|
||||
|
||||
retval = lan743x_hs_syslock_acquire(adapter, LOCK_TIMEOUT_MAX_CNT);
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
|
@ -539,6 +550,9 @@ static int lan743x_hs_eeprom_write(struct lan743x_adapter *adapter,
|
|||
u32 val;
|
||||
int i;
|
||||
|
||||
if (offset + length > MAX_HS_EEPROM_SIZE)
|
||||
return -EINVAL;
|
||||
|
||||
retval = lan743x_hs_syslock_acquire(adapter, LOCK_TIMEOUT_MAX_CNT);
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
|
@ -604,9 +618,9 @@ static int lan743x_ethtool_get_eeprom_len(struct net_device *netdev)
|
|||
struct lan743x_adapter *adapter = netdev_priv(netdev);
|
||||
|
||||
if (adapter->flags & LAN743X_ADAPTER_FLAG_OTP)
|
||||
return MAX_OTP_SIZE;
|
||||
return adapter->is_pci11x1x ? MAX_HS_OTP_SIZE : MAX_OTP_SIZE;
|
||||
|
||||
return MAX_EEPROM_SIZE;
|
||||
return adapter->is_pci11x1x ? MAX_HS_EEPROM_SIZE : MAX_EEPROM_SIZE;
|
||||
}
|
||||
|
||||
static int lan743x_ethtool_get_eeprom(struct net_device *netdev,
|
||||
|
|
Loading…
Reference in New Issue