Kernel patch conditional on package installation

I am in the process of implementing a new protocol package that is primarily a user space daemon with associated script support, but this package does require a small patch be applied to the linux kernel. I am attempting to follow the directions provided in other related posts here (, but I wasn't sure if this description was for kernel patches that are unconditionally applied or not.
For my purposes, I really only want this kernel patch to be applied when my protocol package is installed. Is there an example that I can look at for a similar situation?

Unconditional by (sub-)target. All boards use the same kernel, and often the same root file system (file system is configurable, I believe).

For testing, you might consider a sub-target. I just did this for ath79 and NAND. PR up on github for reference. Look at for starters

I looked at the diff for this PR, but I didn't really understand it... It does not appear to be a kernel patch (in that the change does not include something like the number-changedescr.patch convention) so much as a custom configuration for the kernel. Could you elaborate on how it relates to what I want to do?

When you define a sub-target, like the ath79-nand, it gets its own overrides its directory; kernel config, files, and, I would guess, patches. That commit was mainly intended to show the parts touched; the new directory and subdirectories, kernel config adjustments, image makefile, ...

OK, I will look at the PR changes again with that context.
But just to clarify what I want to do, the module of the kernel that I need to patch is itself not automatically included in the default OpenWRT image. The user would need to explicitly include it via "make menuconfig". For my protocol package, I have created a dependency on this non-default kernel module so that it will be included in the image when a user has selected my package for inclusion via "make menuconfig". Is there nothing I could leverage within the "make menuconfig" infrastructure to force a patched version of the module to be built instead of the normal unpatched version?

Ah, OK, that's a little different than what I thought you were trying to accomplish. It sounds like you need a "custom" kernel module, rather than core changes to the kernel's configuration.

I haven't tried this myself, but what I would try if in your situation (at least as I understand it) would be something like

  • Define a new kmod-xxx-special
  • Write a makefile for it that copies the potentially already patched sources in the kernel tree to another directory
  • Patches those sources
  • Conflicts with kmod-xxx
  • Is required by your-package

Yes, this is similar to the strategy (which I believe you suggested) that I am using to patch changes to the tcpdump utility, where I have modified the Makefile for tcpdump to define a custom version which includes a patch for my protocol package and this version conflicts with the normal tcpdump version in menuconfig.
Where in the directory tree would a custom kmod be defined? Do you know offhand?