Possible double copy of request buffer in AKSPI::pack()
I think there may be an unnecessary data copy in the pack function in AKSPI.cpp. I also think the code could be simplified.
Current code (here it seem slike data is first copied from data to msg and then from msg to mReq):
asynStatus AKSPI::pack(unsigned char type, unsigned char *data,
unsigned short len) {
asynStatus status = asynSuccess;
unsigned char msg[AK_MAX_MSG_SZ] = {0};
int i;
int l = 0;
// build the request
for (i = 0; i < len; i++) {
msg[l++] = *(data + i); // data byte[i]
}
memset(mReq, 0, AK_MAX_MSG_SZ);
memset(mResp, 0, AK_MAX_MSG_SZ);
mReqActSz = 0;
mRespActSz = 0;
mReqSz = l;
// maximum bytes received depend on the operation
if (type == AK_REQ_TYPE_WRITE) {
mRespSz = 0;
} else if (type == AK_REQ_TYPE_READ) {
mRespSz = len;
}
memcpy(mReq, msg, mReqSz);
return status;
}
Simplified code (I think this is equivalent, but there may be something I miss):
asynStatus AKSPI::pack(unsigned char type, unsigned char *data,
unsigned short len) {
memset(mReq, 0, AK_MAX_MSG_SZ);
memset(mResp, 0, AK_MAX_MSG_SZ);
mReqActSz = 0;
mRespActSz = 0;
mReqSz = len;
// maximum bytes received depend on the operation
mRespSz = 0;
if (type == AK_REQ_TYPE_READ) {
mRespSz = len;
}
memcpy(mReq, data, mReqSz);
return asynSuccess;
}