791-v5.13-r8152-adjust-rtl8152_check_firmware-function.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. From f10c9edf47d3fa240d965e151a48c670f5035b73 Mon Sep 17 00:00:00 2001
  2. From: Hayes Wang <[email protected]>
  3. Date: Fri, 16 Apr 2021 16:04:33 +0800
  4. Subject: [PATCH] r8152: adjust rtl8152_check_firmware function
  5. commit a8a7be178e81a3d4b6972cbeb0ccd091ca2f9f89 upstream.
  6. Use bits operations to record and check the firmware.
  7. Signed-off-by: Hayes Wang <[email protected]>
  8. Signed-off-by: David S. Miller <[email protected]>
  9. ---
  10. drivers/net/usb/r8152.c | 51 +++++++++++++++++++++++------------------
  11. 1 file changed, 29 insertions(+), 22 deletions(-)
  12. --- a/drivers/net/usb/r8152.c
  13. +++ b/drivers/net/usb/r8152.c
  14. @@ -874,6 +874,14 @@ struct fw_header {
  15. struct fw_block blocks[];
  16. } __packed;
  17. +enum rtl8152_fw_flags {
  18. + FW_FLAGS_USB = 0,
  19. + FW_FLAGS_PLA,
  20. + FW_FLAGS_START,
  21. + FW_FLAGS_STOP,
  22. + FW_FLAGS_NC,
  23. +};
  24. +
  25. /**
  26. * struct fw_mac - a firmware block used by RTL_FW_PLA and RTL_FW_USB.
  27. * The layout of the firmware block is:
  28. @@ -3800,10 +3808,7 @@ static long rtl8152_check_firmware(struc
  29. {
  30. const struct firmware *fw = rtl_fw->fw;
  31. struct fw_header *fw_hdr = (struct fw_header *)fw->data;
  32. - struct fw_mac *pla = NULL, *usb = NULL;
  33. - struct fw_phy_patch_key *start = NULL;
  34. - struct fw_phy_nc *phy_nc = NULL;
  35. - struct fw_block *stop = NULL;
  36. + unsigned long fw_flags = 0;
  37. long ret = -EFAULT;
  38. int i;
  39. @@ -3832,50 +3837,52 @@ static long rtl8152_check_firmware(struc
  40. goto fail;
  41. goto fw_end;
  42. case RTL_FW_PLA:
  43. - if (pla) {
  44. + if (test_bit(FW_FLAGS_PLA, &fw_flags)) {
  45. dev_err(&tp->intf->dev,
  46. "multiple PLA firmware encountered");
  47. goto fail;
  48. }
  49. - pla = (struct fw_mac *)block;
  50. - if (!rtl8152_is_fw_mac_ok(tp, pla)) {
  51. + if (!rtl8152_is_fw_mac_ok(tp, (struct fw_mac *)block)) {
  52. dev_err(&tp->intf->dev,
  53. "check PLA firmware failed\n");
  54. goto fail;
  55. }
  56. + __set_bit(FW_FLAGS_PLA, &fw_flags);
  57. break;
  58. case RTL_FW_USB:
  59. - if (usb) {
  60. + if (test_bit(FW_FLAGS_USB, &fw_flags)) {
  61. dev_err(&tp->intf->dev,
  62. "multiple USB firmware encountered");
  63. goto fail;
  64. }
  65. - usb = (struct fw_mac *)block;
  66. - if (!rtl8152_is_fw_mac_ok(tp, usb)) {
  67. + if (!rtl8152_is_fw_mac_ok(tp, (struct fw_mac *)block)) {
  68. dev_err(&tp->intf->dev,
  69. "check USB firmware failed\n");
  70. goto fail;
  71. }
  72. + __set_bit(FW_FLAGS_USB, &fw_flags);
  73. break;
  74. case RTL_FW_PHY_START:
  75. - if (start || phy_nc || stop) {
  76. + if (test_bit(FW_FLAGS_START, &fw_flags) ||
  77. + test_bit(FW_FLAGS_NC, &fw_flags) ||
  78. + test_bit(FW_FLAGS_STOP, &fw_flags)) {
  79. dev_err(&tp->intf->dev,
  80. "check PHY_START fail\n");
  81. goto fail;
  82. }
  83. - if (__le32_to_cpu(block->length) != sizeof(*start)) {
  84. + if (__le32_to_cpu(block->length) != sizeof(struct fw_phy_patch_key)) {
  85. dev_err(&tp->intf->dev,
  86. "Invalid length for PHY_START\n");
  87. goto fail;
  88. }
  89. -
  90. - start = (struct fw_phy_patch_key *)block;
  91. + __set_bit(FW_FLAGS_START, &fw_flags);
  92. break;
  93. case RTL_FW_PHY_STOP:
  94. - if (stop || !start) {
  95. + if (test_bit(FW_FLAGS_STOP, &fw_flags) ||
  96. + !test_bit(FW_FLAGS_START, &fw_flags)) {
  97. dev_err(&tp->intf->dev,
  98. "Check PHY_STOP fail\n");
  99. goto fail;
  100. @@ -3886,28 +3893,28 @@ static long rtl8152_check_firmware(struc
  101. "Invalid length for PHY_STOP\n");
  102. goto fail;
  103. }
  104. -
  105. - stop = block;
  106. + __set_bit(FW_FLAGS_STOP, &fw_flags);
  107. break;
  108. case RTL_FW_PHY_NC:
  109. - if (!start || stop) {
  110. + if (!test_bit(FW_FLAGS_START, &fw_flags) ||
  111. + test_bit(FW_FLAGS_STOP, &fw_flags)) {
  112. dev_err(&tp->intf->dev,
  113. "check PHY_NC fail\n");
  114. goto fail;
  115. }
  116. - if (phy_nc) {
  117. + if (test_bit(FW_FLAGS_NC, &fw_flags)) {
  118. dev_err(&tp->intf->dev,
  119. "multiple PHY NC encountered\n");
  120. goto fail;
  121. }
  122. - phy_nc = (struct fw_phy_nc *)block;
  123. - if (!rtl8152_is_fw_phy_nc_ok(tp, phy_nc)) {
  124. + if (!rtl8152_is_fw_phy_nc_ok(tp, (struct fw_phy_nc *)block)) {
  125. dev_err(&tp->intf->dev,
  126. "check PHY NC firmware failed\n");
  127. goto fail;
  128. }
  129. + __set_bit(FW_FLAGS_NC, &fw_flags);
  130. break;
  131. default:
  132. @@ -3921,7 +3928,7 @@ static long rtl8152_check_firmware(struc
  133. }
  134. fw_end:
  135. - if ((phy_nc || start) && !stop) {
  136. + if (test_bit(FW_FLAGS_START, &fw_flags) && !test_bit(FW_FLAGS_STOP, &fw_flags)) {
  137. dev_err(&tp->intf->dev, "without PHY_STOP\n");
  138. goto fail;
  139. }