How to apply a patch for Linux source code

For example, I need to apply this patch for my Linux source code: http://git.kernel.org/cgit/linux/kernel/git/davem/net.git/diff/?id=fe82b3300ec9c0dc4ba871f9a58b265aadf4e186

First, I copy this paragraph to a file in local directory: /usr/src/linux-4.3/patch.file.

"

diff --git a/net/mpls/mpls_iptunnel.c b/net/mpls/mpls_iptunnel.c
index 67591ae..64afd3d 100644
--- a/net/mpls/mpls_iptunnel.c
+++ b/net/mpls/mpls_iptunnel.c
@@ -54,10 +54,10 @@ int mpls_output(struct net *net, struct sock *sk, struct sk_buff *skb)
unsigned int ttl;
 
/* Obtain the ttl */
- if (skb->protocol == htons(ETH_P_IP)) {
+ if (dst->ops->family == AF_INET) {
ttl = ip_hdr(skb)->ttl;
rt = (struct rtable *)dst;
- } else if (skb->protocol == htons(ETH_P_IPV6)) {
+ } else if (dst->ops->family == AF_INET6) {
ttl = ipv6_hdr(skb)->hop_limit;
rt6 = (struct rt6_info *)dst;
} else {

"

and then use this command to do the patch:

# patch < patch.file

and then I got the warning info:

"

can't find file to patch at input line 5
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/net/mpls/mpls_iptunnel.c b/net/mpls/mpls_iptunnel.c
|index 67591ae..64afd3d 100644
|--- a/net/mpls/mpls_iptunnel.c
|+++ b/net/mpls/mpls_iptunnel.c
--------------------------
File to patch:

"

I ignore the warning and input the file name: net/mpls/mpls_iptunnel.c

And then the patch is applied.

posted @ 2016-04-26 16:37  dxh1231  阅读(418)  评论(0编辑  收藏  举报