b43-asm: Fix the reverse search for JMPs before RETs
[b43-tools.git] / assembler / main.c
index f2d2826aa5b2e804bf75506347d8b3b8a0f63aed..3f207baf1ed69e412d4f5a6be1c48e05a52c6607 100644 (file)
@@ -488,8 +488,8 @@ static unsigned int merge_external_jmp_into_opcode(struct assembler_context *ctx
 
        /* This instruction has two fake r0 operands
         * at position 0 and 1. */
-       fake = xmalloc(sizeof(struct operand));
-       fake_reg = xmalloc(sizeof(struct operand));
+       fake = xmalloc(sizeof(*fake));
+       fake_reg = xmalloc(sizeof(*fake_reg));
        fake->type = OPER_REG;
        fake->u.reg = fake_reg;
        fake_reg->type = GPR;
@@ -816,13 +816,16 @@ static void assemble_instruction(struct assembler_context *ctx,
                do_assemble_insn(ctx, insn, 0x002);
                break;
        case OP_RET:
-               if (!list_empty(&ctx->output)) {
-                       /* Get the previous instruction and check whether it
-                        * is a jump instruction. */
-                       out = list_entry(ctx->output.prev, struct code_output, list);
-                       if (out->is_jump_insn) {
-                               asm_error(ctx, "RET instruction directly after "
-                                         "jump instruction. The hardware won't like this.");
+               /* Get the previous instruction and check whether it
+                * is a jump instruction. */
+               list_for_each_entry_reverse(out, &ctx->output, list) {
+                       /* Search the last insn. */
+                       if (out->type == OUT_INSN) {
+                               if (out->is_jump_insn) {
+                                       asm_error(ctx, "RET instruction directly after "
+                                                 "jump instruction. The hardware won't like this.");
+                               }
+                               break;
                        }
                }
                do_assemble_insn(ctx, insn, 0x003);