19 Nov 2015 fzort   » (Journeyer)

So I tried to build a kernel for my lowly Xperia E1 smartphone today. Long story short, the kernel in the tarball I got from Sony's site didn't build out of the box, probably because I used gcc 4.8, which has the super nifty -Wsizeof-pointer-memaccess warning option.

It caught a bunch of facepalm-worthy bugs such as this one, in the akm8963 compass driver (drivers/misc/akm8963.c):

static ssize_t akm8963_sysfs_delay_show(
        struct akm8963_data *akm, char *buf, int pos)
{
        int64_t val;

        mutex_lock(&akm->val_mutex);
        val = akm->delay[pos];
        mutex_unlock(&akm->val_mutex);

        return snprintf(buf,sizeof(buf), "%lld\n", val);
}

This one, in the BlueZ Bluetooth protocol stack (!) (net/bluetooth/hci_conn.c), reminded me of a recent rant by Linus Torvalds:

void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
{
        struct hci_dev *hdev = conn->hdev;
        struct hci_cp_le_ltk_reply cp;
  
        BT_DBG("%p", conn);
 
        memset(&cp, 0, sizeof(cp));
  
        cp.handle = cpu_to_le16(conn->handle);
        memcpy(cp.ltk, ltk, sizeof(ltk));
  
        hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
}

I'm surprised this even works. Weirdly a similar memcpy is correct in the function immediately above this one.

After fixing these I eventually built the kernel, but couldn't get it to run on the phone yet (I think it should run with fastboot boot zImage-dtb). Ah well, I'll figure it out eventually.

By the way, it's very very nice of Sony to provide an official way to unlock the bootloader (that is, disable the kernel/ramdisk image checking in the bootloader), to provide instructions on how to build the kernel on their official blog, and to put the kernels for (most of) their smartphones on github. <3 you, Sony. Very different from a certain Korean smartphone manufacturer (won't name any names, but has a two-letter name).

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!