>From 23113231c7819b2e99854cac1ec4370b06db442c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= Date: Thu, 26 Nov 2020 14:19:51 +0100 Subject: [PATCH] fpga: fpga-sec-mgr: handle trailing newline in filename_store MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The copying of the filename written to the sysfs unconditionally remove the last character, as (I assume) if it were a newline char. For the most cases this is true (e.g. when using `echo` in the shell), but some software writes the filename without a trailing newline, in which the firmware load obviously fails. Fix this by checking for a newline char, and replacing it with '\0' if found. Fixes: 1815cc58d473 ("fpga: sec-mgr: enable secure updates") Signed-off-by: Martin Hundebøll --- drivers/fpga/fpga-sec-mgr.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/fpga/fpga-sec-mgr.c b/drivers/fpga/fpga-sec-mgr.c index 72b61dc173db..d2ce4c682bd9 100644 --- a/drivers/fpga/fpga-sec-mgr.c +++ b/drivers/fpga/fpga-sec-mgr.c @@ -423,12 +423,16 @@ static ssize_t filename_store(struct device *dev, struct device_attribute *attr, goto unlock_exit; } - smgr->filename = kstrndup(buf, count - 1, GFP_KERNEL); + smgr->filename = kstrndup(buf, count, GFP_KERNEL); if (!smgr->filename) { ret = -ENOMEM; goto unlock_exit; } + /* remove trailing newline */ + if (smgr->filename[count - 1] == '\n') + smgr->filename[count - 1] = '\0'; + smgr->err_code = FPGA_SEC_ERR_NONE; smgr->hw_errinfo = 0; smgr->request_cancel = false; -- 2.29.2