[PATCH] drm/amdgpu: update type of buf size to u32 for eeprom functions

Zhou1, Tao Tao.Zhou1 at amd.com
Mon May 20 06:22:15 UTC 2024


[AMD Official Use Only - AMD Internal Distribution Only]


The limit variable in amdgpu_eeprom_xfer is not 0, so the buf_size will be cut into smaller pieces, u16 is enough for __amdgpu_eeprom_xfer.
Anyway, use u32 for __amdgpu_eeprom_xfer and make sure the msgs[1].len is less than U16_MAX is better, will create a new patch for the purpose.

Tao

      _____________________________________________
      From: Zhang, Hawking <Hawking.Zhang at amd.com>
      Sent: Monday, May 20, 2024 11:23 AM
      To: Zhou1, Tao <Tao.Zhou1 at amd.com>; amd-gfx at lists.freedesktop.org
      Cc: Zhou1, Tao <Tao.Zhou1 at amd.com>
      Subject: RE: [PATCH] drm/amdgpu: update type of buf size to u32 for eeprom functions


      [AMD Official Use Only - AMD Internal Distribution Only]



      Hmm... but in __amdgpu_eeprom_xfer, the u32 will still be cut to u16.
      __amdgpu_eeprom_xfer(struct i2c_adapter *i2c_adap, u32 eeprom_addr, u8 *eeprom_buf, u16 buf_size, bool read)

      Regards,
      Hawking

      -----Original Message-----
      From: amd-gfx <amd-gfx-bounces at lists.freedesktop.org<mailto:amd-gfx-bounces at lists.freedesktop.org>> On Behalf Of Tao Zhou
      Sent: Monday, May 20, 2024 10:46
      To: amd-gfx at lists.freedesktop.org<mailto:amd-gfx at lists.freedesktop.org>
      Cc: Zhou1, Tao <Tao.Zhou1 at amd.com<mailto:Tao.Zhou1 at amd.com>>
      Subject: [PATCH] drm/amdgpu: update type of buf size to u32 for eeprom functions

      Avoid overflow issue.

      Signed-off-by: Tao Zhou <tao.zhou1 at amd.com<mailto:tao.zhou1 at amd.com>>
      ---
       drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c | 6 +++---  drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.h | 4 ++--
       2 files changed, 5 insertions(+), 5 deletions(-)

      diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c
      index e71768661ca8..09a34c7258e2 100644
      --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c
      +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c
      @@ -179,7 +179,7 @@ static int __amdgpu_eeprom_xfer(struct i2c_adapter *i2c_adap, u32 eeprom_addr,
        * Returns the number of bytes read/written; -errno on error.
        */
       static int amdgpu_eeprom_xfer(struct i2c_adapter *i2c_adap, u32 eeprom_addr,
      -                       u8 *eeprom_buf, u16 buf_size, bool read)
      +                       u8 *eeprom_buf, u32 buf_size, bool read)
       {
        const struct i2c_adapter_quirks *quirks = i2c_adap->quirks;
        u16 limit;
      @@ -225,7 +225,7 @@ static int amdgpu_eeprom_xfer(struct i2c_adapter *i2c_adap, u32 eeprom_addr,

       int amdgpu_eeprom_read(struct i2c_adapter *i2c_adap,
                       u32 eeprom_addr, u8 *eeprom_buf,
      -                u16 bytes)
      +                u32 bytes)
       {
        return amdgpu_eeprom_xfer(i2c_adap, eeprom_addr, eeprom_buf, bytes,
                                  true);
      @@ -233,7 +233,7 @@ int amdgpu_eeprom_read(struct i2c_adapter *i2c_adap,

       int amdgpu_eeprom_write(struct i2c_adapter *i2c_adap,
                        u32 eeprom_addr, u8 *eeprom_buf,
      -                 u16 bytes)
      +                 u32 bytes)
       {
        return amdgpu_eeprom_xfer(i2c_adap, eeprom_addr, eeprom_buf, bytes,
                                  false);
      diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.h
      index 6935adb2be1f..8083b8253ef4 100644
      --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.h
      +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.h
      @@ -28,10 +28,10 @@

       int amdgpu_eeprom_read(struct i2c_adapter *i2c_adap,
                       u32 eeprom_addr, u8 *eeprom_buf,
      -                u16 bytes);
      +                u32 bytes);

       int amdgpu_eeprom_write(struct i2c_adapter *i2c_adap,
                        u32 eeprom_addr, u8 *eeprom_buf,
      -                 u16 bytes);
      +                 u32 bytes);

       #endif
      --
      2.34.1

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/amd-gfx/attachments/20240520/91254ba6/attachment-0001.htm>


More information about the amd-gfx mailing list