Skip to content

Commit 794ba27

Browse files
ConchuODgregkh
authored andcommitted
firmware: microchip: auto-update: fix poll_complete() to not report spurious timeout errors
commit 83beece upstream. fw_upload's poll_complete() is really intended for use with asynchronous write() implementations - or at least those where the write() loop may terminate without the kernel yet being aware of whether or not the firmware upload has succeeded. For auto-update, write() is only ever called once and will only return when uploading has completed, be that by passing or failing. The core fw_upload code only calls poll_complete() after the final call to write() has returned. However, the poll_complete() implementation in the auto-update driver was written to expect poll_complete() to be called from another context, and it waits for a completion signalled from write(). Since poll_complete() is actually called from the same context, after the write() loop has terminated, wait_for_completion() never sees the completion get signalled and always times out, causing programming to always report a failing. Since write() is full synchronous, and its return value will indicate whether or not programming passed or failed, poll_complete() serves no purpose and can be cut down to simply return FW_UPLOAD_ERR_NONE. Cc: [email protected] Fixes: ec5b0f1 ("firmware: microchip: add PolarFire SoC Auto Update support") Reported-by: Jamie Gibbons <[email protected]> Tested-by: Jamie Gibbons <[email protected]> Signed-off-by: Conor Dooley <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 623848f commit 794ba27

File tree

1 file changed

+7
-35
lines changed

1 file changed

+7
-35
lines changed

drivers/firmware/microchip/mpfs-auto-update.c

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,11 @@
7676
#define AUTO_UPDATE_INFO_SIZE SZ_1M
7777
#define AUTO_UPDATE_BITSTREAM_BASE (AUTO_UPDATE_DIRECTORY_SIZE + AUTO_UPDATE_INFO_SIZE)
7878

79-
#define AUTO_UPDATE_TIMEOUT_MS 60000
80-
8179
struct mpfs_auto_update_priv {
8280
struct mpfs_sys_controller *sys_controller;
8381
struct device *dev;
8482
struct mtd_info *flash;
8583
struct fw_upload *fw_uploader;
86-
struct completion programming_complete;
8784
size_t size_per_bitstream;
8885
bool cancel_request;
8986
};
@@ -156,19 +153,6 @@ static void mpfs_auto_update_cancel(struct fw_upload *fw_uploader)
156153

157154
static enum fw_upload_err mpfs_auto_update_poll_complete(struct fw_upload *fw_uploader)
158155
{
159-
struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle;
160-
int ret;
161-
162-
/*
163-
* There is no meaningful way to get the status of the programming while
164-
* it is in progress, so attempting anything other than waiting for it
165-
* to complete would be misplaced.
166-
*/
167-
ret = wait_for_completion_timeout(&priv->programming_complete,
168-
msecs_to_jiffies(AUTO_UPDATE_TIMEOUT_MS));
169-
if (!ret)
170-
return FW_UPLOAD_ERR_TIMEOUT;
171-
172156
return FW_UPLOAD_ERR_NONE;
173157
}
174158

@@ -349,33 +333,23 @@ static enum fw_upload_err mpfs_auto_update_write(struct fw_upload *fw_uploader,
349333
u32 offset, u32 size, u32 *written)
350334
{
351335
struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle;
352-
enum fw_upload_err err = FW_UPLOAD_ERR_NONE;
353336
int ret;
354337

355-
reinit_completion(&priv->programming_complete);
356-
357338
ret = mpfs_auto_update_write_bitstream(fw_uploader, data, offset, size, written);
358-
if (ret) {
359-
err = FW_UPLOAD_ERR_RW_ERROR;
360-
goto out;
361-
}
339+
if (ret)
340+
return FW_UPLOAD_ERR_RW_ERROR;
362341

363-
if (priv->cancel_request) {
364-
err = FW_UPLOAD_ERR_CANCELED;
365-
goto out;
366-
}
342+
if (priv->cancel_request)
343+
return FW_UPLOAD_ERR_CANCELED;
367344

368345
if (mpfs_auto_update_is_bitstream_info(data, size))
369-
goto out;
346+
return FW_UPLOAD_ERR_NONE;
370347

371348
ret = mpfs_auto_update_verify_image(fw_uploader);
372349
if (ret)
373-
err = FW_UPLOAD_ERR_FW_INVALID;
350+
return FW_UPLOAD_ERR_FW_INVALID;
374351

375-
out:
376-
complete(&priv->programming_complete);
377-
378-
return err;
352+
return FW_UPLOAD_ERR_NONE;
379353
}
380354

381355
static const struct fw_upload_ops mpfs_auto_update_ops = {
@@ -461,8 +435,6 @@ static int mpfs_auto_update_probe(struct platform_device *pdev)
461435
return dev_err_probe(dev, ret,
462436
"The current bitstream does not support auto-update\n");
463437

464-
init_completion(&priv->programming_complete);
465-
466438
fw_uploader = firmware_upload_register(THIS_MODULE, dev, "mpfs-auto-update",
467439
&mpfs_auto_update_ops, priv);
468440
if (IS_ERR(fw_uploader))

0 commit comments

Comments
 (0)