lkml.org 
[lkml]   [2021]   [Aug]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    SubjectRe: [PATCH RFC 1/3] staging: r8188eu: add proper rtw_read* error handling
    Date
    On Friday, August 20, 2021 7:07:36 PM CEST Pavel Skripkin wrote:
    > rtw_read*() functions call usb_read* inside. These functions could fail
    > in some cases; for example: failed to receive control message. These
    > cases should be handled to prevent uninit value bugs, since usb_read*
    > functions blindly return stack variable without checking if this value
    > _actualy_ initialized.
    >
    > To achive it, all usb_read* and rtw_read*() argument list is expanded

    Dear Pavel,

    Please, achive --> achieve.

    > with pointer to error and added error usbctrl_vendorreq() error checking.
    > If transfer is successful error will be initialized to 0 otherwise to
    > error returned from usb_control_msg().
    >
    > To not break the build, added error checking for rtw_read*() call all
    > across the driver.
    >
    > Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
    > ---
    > drivers/staging/r8188eu/core/rtw_debug.c | 79 +++-
    > drivers/staging/r8188eu/core/rtw_efuse.c | 83 +++-
    > drivers/staging/r8188eu/core/rtw_io.c | 18 +-
    > drivers/staging/r8188eu/core/rtw_mp.c | 37 +-
    > drivers/staging/r8188eu/core/rtw_mp_ioctl.c | 20 +-
    > drivers/staging/r8188eu/core/rtw_pwrctrl.c | 6 +-
    > drivers/staging/r8188eu/core/rtw_sreset.c | 7 +-
    > drivers/staging/r8188eu/hal/HalPwrSeqCmd.c | 9 +-
    > drivers/staging/r8188eu/hal/hal_com.c | 22 +-
    > drivers/staging/r8188eu/hal/odm_interface.c | 12 +-
    > drivers/staging/r8188eu/hal/rtl8188e_cmd.c | 37 +-
    > drivers/staging/r8188eu/hal/rtl8188e_dm.c | 6 +-
    > .../staging/r8188eu/hal/rtl8188e_hal_init.c | 198 +++++++--
    > drivers/staging/r8188eu/hal/rtl8188e_phycfg.c | 26 +-
    > drivers/staging/r8188eu/hal/rtl8188e_sreset.c | 20 +-
    > drivers/staging/r8188eu/hal/rtl8188eu_led.c | 17 +-
    > drivers/staging/r8188eu/hal/usb_halinit.c | 394 ++++++++++++++----
    > drivers/staging/r8188eu/hal/usb_ops_linux.c | 16 +-
    > drivers/staging/r8188eu/include/rtw_io.h | 18 +-
    > drivers/staging/r8188eu/os_dep/ioctl_linux.c | 168 +++++---
    > 20 files changed, 941 insertions(+), 252 deletions(-)

    I agree with Philip: please, split this long patch. If I were you, I'd make
    one patch for each of the three rtw_read*() and a fourth patch for usb_read*().

    > --- a/drivers/staging/r8188eu/core/rtw_io.c
    > +++ b/drivers/staging/r8188eu/core/rtw_io.c
    > @@ -34,44 +34,44 @@ jackson@realtek.com.tw
    > #define rtw_cpu_to_le16(val) cpu_to_le16(val)
    > #define rtw_cpu_to_le32(val) cpu_to_le32(val)

    Not related to your patch, these macros are useless and misleading.

    > -u8 _rtw_read8(struct adapter *adapter, u32 addr)
    > +u8 _rtw_read8(struct adapter *adapter, u32 addr, int *error)
    > {
    > u8 r_val;
    > struct io_priv *pio_priv = &adapter->iopriv;
    > struct intf_hdl *pintfhdl = &pio_priv->intf;
    > - u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr);
    > + u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr, int *error);
    >
    >
    > _read8 = pintfhdl->io_ops._read8;
    > - r_val = _read8(pintfhdl, addr);
    > + r_val = _read8(pintfhdl, addr, error);
    >
    > return r_val;
    > }

    I really don't like passing errors through arguments. Why don't you pass
    a storage location where the function save the byte read and instead use the
    return for errors? I think that this would result in a cleaner design. Furthermore,
    it is used everywhere in the kernel.

    > -u16 _rtw_read16(struct adapter *adapter, u32 addr)
    > +u16 _rtw_read16(struct adapter *adapter, u32 addr, int *error)
    > {
    > u16 r_val;
    > struct io_priv *pio_priv = &adapter->iopriv;
    > struct intf_hdl *pintfhdl = &pio_priv->intf;
    > - u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr);
    > + u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr, int *error);
    >
    > _read16 = pintfhdl->io_ops._read16;
    >
    > - r_val = _read16(pintfhdl, addr);
    > + r_val = _read16(pintfhdl, addr, error);
    >
    > return r_val;
    > }

    Same.

    > -u32 _rtw_read32(struct adapter *adapter, u32 addr)
    > +u32 _rtw_read32(struct adapter *adapter, u32 addr, int *error)
    > {
    > u32 r_val;
    > struct io_priv *pio_priv = &adapter->iopriv;
    > struct intf_hdl *pintfhdl = &pio_priv->intf;
    > - u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr);
    > + u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr, int *error);
    >
    > _read32 = pintfhdl->io_ops._read32;
    >
    > - r_val = _read32(pintfhdl, addr);
    > + r_val = _read32(pintfhdl, addr, error);
    >
    > return r_val;
    > }

    Same.

    I'm done for now: too many lines to read all at once :)

    Regards,

    Fabio


    \
     
     \ /
      Last update: 2021-08-21 07:56    [W:7.919 / U:0.236 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site