diff mbox series

[6/7] usb: typec: ucsi: add check for supported vendor

Message ID 20190118011302.16256-1-ajayg@nvidia.com (mailing list archive)
State New, archived
Headers show
Series Add support for firmware update on Cypres CCGx | expand

Commit Message

Ajay Gupta Jan. 18, 2019, 1:13 a.m. UTC
Added check to see the currently flashed or new firmware being
flashed is from a supported vendor.

Signed-off-by: Ajay Gupta <ajayg@nvidia.com>
---
 drivers/usb/typec/ucsi/ucsi_ccg.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

Comments

Heikki Krogerus Jan. 18, 2019, 3:29 p.m. UTC | #1
On Thu, Jan 17, 2019 at 05:13:02PM -0800, Ajay Gupta wrote:
> Added check to see the currently flashed or new firmware being
> flashed is from a supported vendor.

Why separate patch for this?

thanks,
Ajay Gupta Jan. 24, 2019, 6:04 p.m. UTC | #2
Hi Heikki,
> From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Sent: Friday, January 18, 2019 7:30 AM
> To: Ajay Gupta <ajayg@nvidia.com>
> Cc: linux-usb@vger.kernel.org
> Subject: Re: [PATCH 6/7] usb: typec: ucsi: add check for supported vendor
> 
> On Thu, Jan 17, 2019 at 05:13:02PM -0800, Ajay Gupta wrote:
> > Added check to see the currently flashed or new firmware being flashed
> > is from a supported vendor.
> 
> Why separate patch for this?
I thought its vendor specific changes; so added separately, looks like need to 
merge to patch 5/7.

Thanks
> nvpublic
> thanks,
> 
> --
> heikki
diff mbox series

Patch

diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c
index 6069a9f60d1e..1aa6ede764b5 100644
--- a/drivers/usb/typec/ucsi/ucsi_ccg.c
+++ b/drivers/usb/typec/ucsi/ucsi_ccg.c
@@ -775,6 +775,30 @@  static int ccg_cmd_validate_fw(struct ucsi_ccg *uc, unsigned int fwid)
 	return 0;
 }
 
+static bool ccg_check_vendor_version(struct ucsi_ccg *uc,
+				     struct version_format *app,
+				     struct fw_config_table *fw_cfg)
+{
+	struct device *dev = uc->dev;
+
+	/* Check if the fw build is for supported vendors.
+	 * Add all supported vendors here.
+	 */
+	if (app->build != (('n' << 8) | 'v')) {
+		dev_info(dev, "current fw is not from supported vendor\n");
+		return false;
+	}
+
+	/* Check if the new fw build is for supported vendors
+	 * Add all supported vendors here.
+	 */
+	if (fw_cfg->app.build != (('n' << 8) | 'v')) {
+		dev_info(dev, "new fw is not from supported vendor\n");
+		return false;
+	}
+	return true;
+}
+
 static bool ccg_check_fw_version(struct ucsi_ccg *uc, const char *fw_name,
 				 struct version_format *app)
 {
@@ -814,6 +838,9 @@  static bool ccg_check_fw_version(struct ucsi_ccg *uc, const char *fw_name,
 	dev_dbg(dev, "compare current %08x and new version %08x\n",
 		cur_version, new_version);
 
+	if (!ccg_check_vendor_version(uc, app, &fw_cfg))
+		goto not_supported_version;
+
 	if (new_version > cur_version) {
 		dev_dbg(dev, "new firmware file version is later\n");
 		is_later = true;
@@ -821,6 +848,7 @@  static bool ccg_check_fw_version(struct ucsi_ccg *uc, const char *fw_name,
 		dev_dbg(dev, "new firmware file version is same or earlier\n");
 	}
 
+not_supported_version:
 not_signed_fw:
 	release_firmware(fw);
 	return is_later;