diff mbox series

[net-next,5/5] ptp: ocp: remove flash image header check fallback

Message ID 20221017215947.7438-6-vfedorenko@novek.ru (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series ptp: ocp: add support for Orolia ART-CARD | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 0 this patch: 2
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang fail Errors and warnings before: 2 this patch: 3
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 0 this patch: 2
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 13 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Vadim Fedorenko Oct. 17, 2022, 9:59 p.m. UTC
From: Vadim Fedorenko <vadfed@fb.com>

Previously there was a fallback mode to flash firmware image without
proper header. But now we have different supported vendors and flashing
wrong image could destroy the hardware. Remove fallback mode and force
header check. Both vendors have published firmware images with headers.

Signed-off-by: Vadim Fedorenko <vadfed@fb.com>
---
 drivers/ptp/ptp_ocp.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

kernel test robot Oct. 18, 2022, 2:57 a.m. UTC | #1
Hi Vadim,

I love your patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Vadim-Fedorenko/ptp-ocp-add-support-for-Orolia-ART-CARD/20221018-060138
patch link:    https://lore.kernel.org/r/20221017215947.7438-6-vfedorenko%40novek.ru
patch subject: [PATCH net-next 5/5] ptp: ocp: remove flash image header check fallback
config: i386-allyesconfig
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/6a4a00e6e58c585d9fe182377e261e531593f143
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Vadim-Fedorenko/ptp-ocp-add-support-for-Orolia-ART-CARD/20221018-060138
        git checkout 6a4a00e6e58c585d9fe182377e261e531593f143
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/ptp/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/ptp/ptp_ocp.c: In function 'ptp_ocp_devlink_fw_image':
>> drivers/ptp/ptp_ocp.c:1569:1: warning: label 'out' defined but not used [-Wunused-label]
    1569 | out:
         | ^~~


vim +/out +1569 drivers/ptp/ptp_ocp.c

773bda96492153 Jonathan Lemon  2021-08-03  1526  
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1527  static int
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1528  ptp_ocp_devlink_fw_image(struct devlink *devlink, const struct firmware *fw,
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1529  			 const u8 **data, size_t *size)
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1530  {
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1531  	struct ptp_ocp *bp = devlink_priv(devlink);
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1532  	const struct ptp_ocp_firmware_header *hdr;
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1533  	size_t offset, length;
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1534  	u16 crc;
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1535  
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1536  	hdr = (const struct ptp_ocp_firmware_header *)fw->data;
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1537  	if (memcmp(hdr->magic, OCP_FIRMWARE_MAGIC_HEADER, 4)) {
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1538  		devlink_flash_update_status_notify(devlink,
6a4a00e6e58c58 Vadim Fedorenko 2022-10-18  1539  			"No firmware header found, cancel firmware upgrade",
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1540  			NULL, 0, 0);
6a4a00e6e58c58 Vadim Fedorenko 2022-10-18  1541  		return -EINVAL;
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1542  	}
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1543  
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1544  	if (be16_to_cpu(hdr->pci_vendor_id) != bp->pdev->vendor ||
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1545  	    be16_to_cpu(hdr->pci_device_id) != bp->pdev->device) {
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1546  		devlink_flash_update_status_notify(devlink,
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1547  			"Firmware image compatibility check failed",
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1548  			NULL, 0, 0);
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1549  		return -EINVAL;
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1550  	}
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1551  
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1552  	offset = sizeof(*hdr);
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1553  	length = be32_to_cpu(hdr->image_size);
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1554  	if (length != (fw->size - offset)) {
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1555  		devlink_flash_update_status_notify(devlink,
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1556  			"Firmware image size check failed",
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1557  			NULL, 0, 0);
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1558  		return -EINVAL;
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1559  	}
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1560  
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1561  	crc = crc16(0xffff, &fw->data[offset], length);
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1562  	if (be16_to_cpu(hdr->crc) != crc) {
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1563  		devlink_flash_update_status_notify(devlink,
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1564  			"Firmware image CRC check failed",
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1565  			NULL, 0, 0);
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1566  		return -EINVAL;
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1567  	}
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1568  
3c3673bde50c31 Vadim Fedorenko 2022-05-19 @1569  out:
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1570  	*data = &fw->data[offset];
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1571  	*size = length;
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1572  
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1573  	return 0;
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1574  }
3c3673bde50c31 Vadim Fedorenko 2022-05-19  1575
diff mbox series

Patch

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 82d17b90fe16..3788daf1e541 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -1536,11 +1536,9 @@  ptp_ocp_devlink_fw_image(struct devlink *devlink, const struct firmware *fw,
 	hdr = (const struct ptp_ocp_firmware_header *)fw->data;
 	if (memcmp(hdr->magic, OCP_FIRMWARE_MAGIC_HEADER, 4)) {
 		devlink_flash_update_status_notify(devlink,
-			"No firmware header found, flashing raw image",
+			"No firmware header found, cancel firmware upgrade",
 			NULL, 0, 0);
-		offset = 0;
-		length = fw->size;
-		goto out;
+		return -EINVAL;
 	}
 
 	if (be16_to_cpu(hdr->pci_vendor_id) != bp->pdev->vendor ||