Skip to content

Commit d930eb4

Browse files
committed
firmware: microchip: use scope-based cleanup where possible
There's a bunch of structs created and freed every time the mailbox is used. Move them to use the scope-based cleanup infrastructure to avoid manually tearing them down. mpfs_auto_update_available() didn't free the memory that it used (albeit it allocated exactly once during probe) so that gets moved over too. Signed-off-by: Conor Dooley <[email protected]>
1 parent e277026 commit d930eb4

File tree

1 file changed

+16
-43
lines changed

1 file changed

+16
-43
lines changed

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

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -175,28 +175,17 @@ static enum fw_upload_err mpfs_auto_update_poll_complete(struct fw_upload *fw_up
175175
static int mpfs_auto_update_verify_image(struct fw_upload *fw_uploader)
176176
{
177177
struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle;
178-
struct mpfs_mss_response *response;
179-
struct mpfs_mss_msg *message;
180-
u32 *response_msg;
178+
u32 *response_msg __free(kfree) =
179+
kzalloc(AUTO_UPDATE_FEATURE_RESP_SIZE * sizeof(*response_msg), GFP_KERNEL);
180+
struct mpfs_mss_response *response __free(kfree) =
181+
kzalloc(sizeof(struct mpfs_mss_response), GFP_KERNEL);
182+
struct mpfs_mss_msg *message __free(kfree) =
183+
kzalloc(sizeof(struct mpfs_mss_msg), GFP_KERNEL);
181184
int ret;
182185

183-
response_msg = devm_kzalloc(priv->dev, AUTO_UPDATE_FEATURE_RESP_SIZE * sizeof(*response_msg),
184-
GFP_KERNEL);
185-
if (!response_msg)
186+
if (!response_msg || !response || !message)
186187
return -ENOMEM;
187188

188-
response = devm_kzalloc(priv->dev, sizeof(struct mpfs_mss_response), GFP_KERNEL);
189-
if (!response) {
190-
ret = -ENOMEM;
191-
goto free_response_msg;
192-
}
193-
194-
message = devm_kzalloc(priv->dev, sizeof(struct mpfs_mss_msg), GFP_KERNEL);
195-
if (!message) {
196-
ret = -ENOMEM;
197-
goto free_response;
198-
}
199-
200189
/*
201190
* The system controller can verify that an image in the flash is valid.
202191
* Rather than duplicate the check in this driver, call the relevant
@@ -218,20 +207,12 @@ static int mpfs_auto_update_verify_image(struct fw_upload *fw_uploader)
218207
ret = mpfs_blocking_transaction(priv->sys_controller, message);
219208
if (ret | response->resp_status) {
220209
dev_warn(priv->dev, "Verification of Upgrade Image failed!\n");
221-
ret = ret ? ret : -EBADMSG;
222-
goto free_message;
210+
return ret ? ret : -EBADMSG;
223211
}
224212

225213
dev_info(priv->dev, "Verification of Upgrade Image passed!\n");
226214

227-
free_message:
228-
devm_kfree(priv->dev, message);
229-
free_response:
230-
devm_kfree(priv->dev, response);
231-
free_response_msg:
232-
devm_kfree(priv->dev, response_msg);
233-
234-
return ret;
215+
return 0;
235216
}
236217

237218
static int mpfs_auto_update_set_image_address(struct mpfs_auto_update_priv *priv,
@@ -406,23 +387,15 @@ static const struct fw_upload_ops mpfs_auto_update_ops = {
406387

407388
static int mpfs_auto_update_available(struct mpfs_auto_update_priv *priv)
408389
{
409-
struct mpfs_mss_response *response;
410-
struct mpfs_mss_msg *message;
411-
u32 *response_msg;
390+
u32 *response_msg __free(kfree) =
391+
kzalloc(AUTO_UPDATE_FEATURE_RESP_SIZE * sizeof(*response_msg), GFP_KERNEL);
392+
struct mpfs_mss_response *response __free(kfree) =
393+
kzalloc(sizeof(struct mpfs_mss_response), GFP_KERNEL);
394+
struct mpfs_mss_msg *message __free(kfree) =
395+
kzalloc(sizeof(struct mpfs_mss_msg), GFP_KERNEL);
412396
int ret;
413397

414-
response_msg = devm_kzalloc(priv->dev,
415-
AUTO_UPDATE_FEATURE_RESP_SIZE * sizeof(*response_msg),
416-
GFP_KERNEL);
417-
if (!response_msg)
418-
return -ENOMEM;
419-
420-
response = devm_kzalloc(priv->dev, sizeof(struct mpfs_mss_response), GFP_KERNEL);
421-
if (!response)
422-
return -ENOMEM;
423-
424-
message = devm_kzalloc(priv->dev, sizeof(struct mpfs_mss_msg), GFP_KERNEL);
425-
if (!message)
398+
if (!response_msg || !response || !message)
426399
return -ENOMEM;
427400

428401
/*

0 commit comments

Comments
 (0)