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

mailbox: pcc: Refactor error handling in irq handler into separate function

The existing error handling logic in pcc_mbox_irq() is intermixed with the
main flow of the function. The command complete check and the complete
complete update/acknowledgment are nicely factored into separate functions.

Moves error detection and clearing logic into a separate function called:
pcc_mbox_error_check_and_clear() by extracting error-handling logic from
pcc_mbox_irq().

This ensures error checking and clearing are handled separately and it
improves maintainability by keeping the IRQ handler focused on processing
events.

Acked-by: Huisong Li <lihuisong@huawei.com>
Tested-by: Huisong Li <lihuisong@huawei.com>
Tested-by: Adam Young <admiyo@os.amperecomputing.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com>

authored by

Sudeep Holla and committed by
Jassi Brar
3a675f50 d181acea

+20 -10
+20 -10
drivers/mailbox/pcc.c
··· 269 269 return !!val; 270 270 } 271 271 272 + static int pcc_mbox_error_check_and_clear(struct pcc_chan_info *pchan) 273 + { 274 + u64 val; 275 + int ret; 276 + 277 + ret = pcc_chan_reg_read(&pchan->error, &val); 278 + if (ret) 279 + return ret; 280 + 281 + val &= pchan->error.status_mask; 282 + if (val) { 283 + val &= ~pchan->error.status_mask; 284 + pcc_chan_reg_write(&pchan->error, val); 285 + return -EIO; 286 + } 287 + 288 + return 0; 289 + } 290 + 272 291 static void check_and_ack(struct pcc_chan_info *pchan, struct mbox_chan *chan) 273 292 { 274 293 struct acpi_pcct_ext_pcc_shared_memory pcc_hdr; ··· 328 309 { 329 310 struct pcc_chan_info *pchan; 330 311 struct mbox_chan *chan = p; 331 - u64 val; 332 - int ret; 333 312 334 313 pchan = chan->con_priv; 335 314 ··· 341 324 if (!pcc_mbox_cmd_complete_check(pchan)) 342 325 return IRQ_NONE; 343 326 344 - ret = pcc_chan_reg_read(&pchan->error, &val); 345 - if (ret) 327 + if (pcc_mbox_error_check_and_clear(pchan)) 346 328 return IRQ_NONE; 347 - val &= pchan->error.status_mask; 348 - if (val) { 349 - val &= ~pchan->error.status_mask; 350 - pcc_chan_reg_write(&pchan->error, val); 351 - return IRQ_NONE; 352 - } 353 329 354 330 /* 355 331 * Clear this flag after updating interrupt ack register and just