Message ID | 20210523211409.210304-2-huobean@gmail.com (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show |
Series | Three minor changes for UFS | expand |
On 5/23/21 2:14 PM, Bean Huo wrote:
> + rq_rsp = (struct utp_upiu_req *)hba->lrb[tag].ucd_rsp_ptr;
So a pointer to a response (hba->lrb[tag].ucd_rsp_ptr) is cast to a
pointer to a request (struct utp_upiu_req *)? That seems really odd to
me. Please explain.
Bart.
On Sun, 2021-05-23 at 18:24 -0700, Bart Van Assche wrote: > On 5/23/21 2:14 PM, Bean Huo wrote: > > > + rq_rsp = (struct utp_upiu_req *)hba- > > >lrb[tag].ucd_rsp_ptr; > > > So a pointer to a response (hba->lrb[tag].ucd_rsp_ptr) is cast to a > > pointer to a request (struct utp_upiu_req *)? That seems really odd > to > > me. Please explain. Bart, these two structures have the same size, and inside the structures, the both unions have the same members(not exactly 100% identical). struct utp_upiu_rsp { struct utp_upiu_header header; union { struct utp_cmd_rsp sr; struct utp_upiu_query qr; }; }; struct utp_upiu_req { struct utp_upiu_header header; union { struct utp_upiu_cmd sc; struct utp_upiu_query qr; struct utp_upiu_query uc; }; }; Use one point for response and request both, no problem here. It is true that looks very ood, and very difficult to read them. If this is problem, I can change the code, let them more readable. how do you think? Bean
On 5/25/21 12:28 PM, Bean Huo wrote: > If this is problem, I can change the code, let them more readable. > > how do you think? A long explanation was needed to show that the patch is correct. I think this shows that the code is confusing :-) Hence please use the struct utp_upiu_rsp type when interpreting a pointer as a response. Thanks, Bart.
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index c382260e0cf7..dc5f13ccf176 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -300,13 +300,18 @@ static void ufshcd_scsi_block_requests(struct ufs_hba *hba) static void ufshcd_add_cmd_upiu_trace(struct ufs_hba *hba, unsigned int tag, enum ufs_trace_str_t str_t) { - struct utp_upiu_req *rq = hba->lrb[tag].ucd_req_ptr; + struct utp_upiu_req *rq_rsp; if (!trace_ufshcd_upiu_enabled()) return; - trace_ufshcd_upiu(dev_name(hba->dev), str_t, &rq->header, &rq->sc.cdb, - UFS_TSF_CDB); + if (str_t == UFS_CMD_SEND) + rq_rsp = hba->lrb[tag].ucd_req_ptr; + else + rq_rsp = (struct utp_upiu_req *)hba->lrb[tag].ucd_rsp_ptr; + + trace_ufshcd_upiu(dev_name(hba->dev), str_t, &rq_rsp->header, + &rq_rsp->sc.cdb, UFS_TSF_CDB); } static void ufshcd_add_query_upiu_trace(struct ufs_hba *hba,