Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <conor.dooley@microchip.com>

+16 -43
+16 -43
drivers/firmware/microchip/mpfs-auto-update.c
··· 175 175 static int mpfs_auto_update_verify_image(struct fw_upload *fw_uploader) 176 176 { 177 177 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); 181 184 int ret; 182 185 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) 186 187 return -ENOMEM; 187 - 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 188 200 189 /* 201 190 * The system controller can verify that an image in the flash is valid. ··· 207 218 ret = mpfs_blocking_transaction(priv->sys_controller, message); 208 219 if (ret | response->resp_status) { 209 220 dev_warn(priv->dev, "Verification of Upgrade Image failed!\n"); 210 - ret = ret ? ret : -EBADMSG; 211 - goto free_message; 221 + return ret ? ret : -EBADMSG; 212 222 } 213 223 214 224 dev_info(priv->dev, "Verification of Upgrade Image passed!\n"); 215 225 216 - free_message: 217 - devm_kfree(priv->dev, message); 218 - free_response: 219 - devm_kfree(priv->dev, response); 220 - free_response_msg: 221 - devm_kfree(priv->dev, response_msg); 222 - 223 - return ret; 226 + return 0; 224 227 } 225 228 226 229 static int mpfs_auto_update_set_image_address(struct mpfs_auto_update_priv *priv, ··· 387 406 388 407 static int mpfs_auto_update_available(struct mpfs_auto_update_priv *priv) 389 408 { 390 - struct mpfs_mss_response *response; 391 - struct mpfs_mss_msg *message; 392 - u32 *response_msg; 409 + u32 *response_msg __free(kfree) = 410 + kzalloc(AUTO_UPDATE_FEATURE_RESP_SIZE * sizeof(*response_msg), GFP_KERNEL); 411 + struct mpfs_mss_response *response __free(kfree) = 412 + kzalloc(sizeof(struct mpfs_mss_response), GFP_KERNEL); 413 + struct mpfs_mss_msg *message __free(kfree) = 414 + kzalloc(sizeof(struct mpfs_mss_msg), GFP_KERNEL); 393 415 int ret; 394 416 395 - response_msg = devm_kzalloc(priv->dev, 396 - AUTO_UPDATE_FEATURE_RESP_SIZE * sizeof(*response_msg), 397 - GFP_KERNEL); 398 - if (!response_msg) 399 - return -ENOMEM; 400 - 401 - response = devm_kzalloc(priv->dev, sizeof(struct mpfs_mss_response), GFP_KERNEL); 402 - if (!response) 403 - return -ENOMEM; 404 - 405 - message = devm_kzalloc(priv->dev, sizeof(struct mpfs_mss_msg), GFP_KERNEL); 406 - if (!message) 417 + if (!response_msg || !response || !message) 407 418 return -ENOMEM; 408 419 409 420 /*