Patching a module

Hi,
I would like to apply the patch suggested in this post but I don’t know how to process:

Sorry for the basic question but I haven’t found the documentation explaining how to patch a module and update it on my board.

Hi elieva,

You can google it to find some example, such as below links:
https://www.kernel.org/doc/html/v4.18/process/applying-patches.html

You will still want to see the URL from @kaycc, but a comment on this:

diff --git a/drivers/spi/spi-tegra114.c b/drivers/spi/spi-tegra114.c
index d6e50c9..cc6c820 100644
--- a/drivers/spi/spi-tegra114.c
+++ b/drivers/spi/spi-tegra114.c
@@ -1455,10 +1455,8 @@ static int tegra_spi_transfer_one_message(struct spi_master *master,
                msg->actual_length += xfer->len;

 complete_xfer:
-               if (prefer_last_used_cs)
                        cmd1 = tspi->command1_reg;
-               else
-                       cmd1 = tspi->def_command1_reg;
+
                if (ret < 0 || skip) {
                        if (cstate && cstate->cs_gpio_valid)
                                gpio_set_value(spi->cs_gpio, gval);

There are tools to work directly with “diff” files (the “patch” tool). The patch itself indicates the file being updated is:
drivers/spi/spi-tegra114.c

This indicates that at approximately line 1455, looking at editing 10 lines of code, the result will be only 8 lines after the edit:
@@ -1455,10 +1455,8 @@

Lines prefixed with a “-” will be removed, and lines with a “+” will be inserted. Often a “-” and a “+” occur together to indicate the line is edited. If only a “-” occurs, then the line is removed; if only a “+” occurs, then a new line is created. The “patch” command will do this for you, but you can kind of follow the source code in the original file and see how it goes together.

Patch tool “failed hunk” implies the patch for that part of the code was probably already in place, or else the file is so different than the expected file that patch could not figure it out.

The file itself is from the kernel source. At the top/root of the kernel source you should be able to:

cd /where/ever/the/kernel/source/is
# Note: If using the patch tool, then this is where the patch commands would be issued from.
cd drivers/spi/
ls spi-tegra114.c
# Edit spi-tegra114.c with your favorite editor. The `patch` tool is designed to read patch
# (diff) files and perform this automatically if you don't want to do it manually.
# Now cd back to where/ever/the/kernel/source/is and build the kernel after configuring
# just like any other kernel build. You're probably just building a module, don't know, but
# the configuration should be set up correctly prior to building either a full kernel or a
# module.
1 Like