iommu/arm-smmu-v3: Properly handle the return value of arm_smmu_cmdq_build_cmd()
authorZhen Lei <thunder.leizhen@huawei.com>
Wed, 18 Aug 2021 08:04:51 +0000 (16:04 +0800)
committerWill Deacon <will@kernel.org>
Mon, 4 Oct 2021 11:21:13 +0000 (12:21 +0100)
1. Build command CMD_SYNC cannot fail. So the return value can be ignored.
2. The arm_smmu_cmdq_build_cmd() almost never fails, the addition of
   "unlikely()" can optimize the instruction pipeline.
3. Check the return value in arm_smmu_cmdq_batch_add().

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20210818080452.2079-2-thunder.leizhen@huawei.com
Signed-off-by: Will Deacon <will@kernel.org>
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c

index 6340a88a175568b17f76477927f6309268ea47d5..f5848b351b1935900e54c69c1a9c76b88e409011 100644 (file)
@@ -409,10 +409,7 @@ static void __arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu,
                dev_err(smmu->dev, "\t0x%016llx\n", (unsigned long long)cmd[i]);
 
        /* Convert the erroneous command into a CMD_SYNC */
-       if (arm_smmu_cmdq_build_cmd(cmd, &cmd_sync)) {
-               dev_err(smmu->dev, "failed to convert to CMD_SYNC\n");
-               return;
-       }
+       arm_smmu_cmdq_build_cmd(cmd, &cmd_sync);
 
        queue_write(Q_ENT(q, cons), cmd, q->ent_dwords);
 }
@@ -860,7 +857,7 @@ static int __arm_smmu_cmdq_issue_cmd(struct arm_smmu_device *smmu,
 {
        u64 cmd[CMDQ_ENT_DWORDS];
 
-       if (arm_smmu_cmdq_build_cmd(cmd, ent)) {
+       if (unlikely(arm_smmu_cmdq_build_cmd(cmd, ent))) {
                dev_warn(smmu->dev, "ignoring unknown CMDQ opcode 0x%x\n",
                         ent->opcode);
                return -EINVAL;
@@ -885,11 +882,20 @@ static void arm_smmu_cmdq_batch_add(struct arm_smmu_device *smmu,
                                    struct arm_smmu_cmdq_batch *cmds,
                                    struct arm_smmu_cmdq_ent *cmd)
 {
+       int index;
+
        if (cmds->num == CMDQ_BATCH_ENTRIES) {
                arm_smmu_cmdq_issue_cmdlist(smmu, cmds->cmds, cmds->num, false);
                cmds->num = 0;
        }
-       arm_smmu_cmdq_build_cmd(&cmds->cmds[cmds->num * CMDQ_ENT_DWORDS], cmd);
+
+       index = cmds->num * CMDQ_ENT_DWORDS;
+       if (unlikely(arm_smmu_cmdq_build_cmd(&cmds->cmds[index], cmd))) {
+               dev_warn(smmu->dev, "ignoring unknown CMDQ opcode 0x%x\n",
+                        cmd->opcode);
+               return;
+       }
+
        cmds->num++;
 }