Jump to content
Nytro

[RST] Kernel patches

Recommended Posts

Am incercat sa imi compilez si eu un kernel ca tot omul, si am vazut ca mai apar unele erori la compilare. Si de ce sa nu incerc sa le rezolv, daca tot nu e greu?

Si am cautat in fisierul cu pricina, era vorba de un switch() pe o variabila care era de tipul enum v4l2_mbus_pixelcode. Acel switch avea un "case 0:" iar tipul enum v4l2_mbus_pixelcode nu continea aceasta valoare, asta fiind cauza avertismentului la compilare.

In prima instanta am modificat header-ul care definea acea structura, dar am vorbit cu maintainer-ul in cauza si am decis ca e mai bine sa scot acel "case 0" deoarece este inutil.

Cu alte cuvinte, patch-ul (un fel de "Hello world" al patch-urilor, dar totusi un patch) inseamna de fapt 3 linii scoase din fisierul "/drivers/media/video/mt9v022.c". Dar e si asta util, pe langa faptul ca nu veti mai primi eroare la compilare, am scapat si de 3 linii de cod inutile. Deci kernelu vostru ca fi mai mic si mai rapid :))

Screenshot cu mail-ul trimis: http://i55.tinypic.com/345k77p.png

Am ascuns mail-ul meu, deoarece nu am trimis de pe nytro_rst@yahoo.com, ci de pe un alt mail pe care il folosesc mai frecvent.

Patch-ul:

--- a/drivers/media/video/mt9v022.c    2010-08-27 02:47:12.000000000 +0300
+++ b/drivers/media/video/mt9v022.c 2010-09-01 16:12:00.704505851 +0300
@@ -402,9 +402,6 @@
if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATC)
return -EINVAL;
break;
- case 0:
- /* No format change, only geometry */
- break;
default:
return -EINVAL;
}

Stiu ca nu e cine stie ce, dar cred ca e un inceput bun.

Oricum, am mai trimis 2 patch-uri (insa doar 1 e trimis corect), dar nu am primit raspuns.

PS: Patch-ul nu a fost inca vazut si aprobat de Linus, dar nu vad de ce nu ar face-o.

Am incercat sa ma fac util :)

Edited by Nytro
Link to comment
Share on other sites

Bravo hombre. Cam acum un an era plin la comments de gen <--fuck...etc-->

Am o rugaminte, daca ajungi maintainer poate scapi de ele. Il reduci cu 33%

Ex:

fs/binfmt_aout.c: /* Fuck me plenty... */

drivers/ide/pci/cmd640.c: * These chips are basically fucked by design, and getting this driver

.......................................................................

uite o statistica

Link to comment
Share on other sites

Probabil o sa apara si acest patch in cine stie ce versiune urmatoare de kernel:

--- a/fs/xfs/xfs_dir2_data.h    2010-09-02 11:13:11.632007536 +0300
+++ b/fs/xfs/xfs_dir2_data.h 2010-09-02 11:13:28.080006488 +0300
@@ -87,7 +87,7 @@
typedef struct xfs_dir2_data_entry {
__be64 inumber; /* inode number */
__u8 namelen; /* name length */
- __u8 name[1]; /* name bytes, no null */
+ __u8 name[2]; /* name bytes, no null */
/* variable offset */
__be16 tag; /* starting offset of us */
} xfs_dir2_data_entry_t;

E vorba de un vector cu un singur element, dar se folosesc doua elemente, si apare o eroare urata. Se foloseste name[1] cand nu exista decat name[0].

Si acum discut cu cu Alex Elder, maintainer-ul, despre un alt patch dar pe acela nu l-am trimis cum trebuia.

Edit: Va fi reparat si celalalt bug, e cam prostie avertismentul generat:

fs/xfs/xfs_alloc.c: In function ‘xfs_alloc_ag_vextent_near’:
fs/xfs/xfs_alloc.c:694:15: warning: ‘ltlena’ may be used uninitialized in this
function
fs/xfs/xfs_alloc.c:683:15: warning: ‘gtlena’ may be used uninitialized in this
function

Acele variabile sunt initializate in niste expresii conditionate, de aceea apare acel avertisment, insa in practica nu e nici o problema. Dar e urat sa apara astfel de erori la compilarea kernelului.

Rezolvarea e banala, initializarea acelor variabile cu 0.

Edited by Nytro
Link to comment
Share on other sites

Eu unul n-am avut probleme la compilare cu sursele luate din repository de la ubuntu, cei de la ubuntu inainte sa dea drumu in updateuri iau la mana si corecteaza tot mai putin ce e non-free, gen driverele de la placa video, unele wifi...

Felicitari si la mai multe!

PS: maine-poimaine te vedem in team-ul de la kernel tinand conferinte. ;)

Link to comment
Share on other sites

Da, probabil cei de la Ubuntu repara astfel de probleme (banale) si le pastreaza decat pentru ei. Ceea ce inseamna ca sunt nesimtiti. Nu contribuie mai deloc la kernel, sunt un fel de leecheri.

Oricum, inainte de compilare, am selectat mai toate optiunile, sa verific unde apar erori sau avertismente. Si la ultima versiune am primit o eroare fatala, dar nu am avut timp sa ma uit sa vad despre ce e vorba, a inceput scoala :-".

O sa mai vin cu catea astfel de bugfix-uri, apoi cine stie, poate o sa mai invat cate ceva si trec mai departe. :)

Edit: Pentru avertismentele acelea (xfs_alloc.c) a aparut patch-ul:

http://www.kernel.org/diff/diffview.cgi?file=%2Fpub%2Flinux%2Fkernel%2Fv2.6%2Fnext%2Fpatch-v2.6.36-rc4-next-20100917.bz2;z=3819

:D

Edited by Nytro
Link to comment
Share on other sites

Ma bucur sa vad ca exista oameni interesati si de aceste lucruri. Imi place aceasta activitate.

Am mai trimis unul, dar nu am stiut exact cui, l-am trimis la "trivial".

[PATCH] /init/main.c (2.6.34.7) Fixed useless compile warning

From: Ionut Gabriel Popescu <*******@yahoo.com>

First of all, I am really sorry, I didn't know where to send this, I didn't know
who is the maintainer of that (/init) section.
This is not practically a bug, but the compiler can't be sure about that. The
calltime structure is initialized in the first if and it is used in same
condition if downer, but the compiler doesn't know that is the same condition,
that si always the same and throw this warning:
init/main.c: In function ‘do_one_initcall’:
init/main.c:722:10: warning: ‘calltime.tv64’ may be used uninitialized in this
function
And this is ugly.
It is very easy to fix it, just initialize the calltime structure with 0. It
isn't necessary, but the compiler won't throw that ugly warning anymore.
I am sorry for sending this to you, can you send it where it would be coreect
please? Thanks.
Patch:

Signed-off-by: Ionut Gabriel Popescu <*******@yahoo.com>
---

--- a/init/main.c 2010-09-17 10:37:25.496004183 +0300
+++ b/init/main.c 2010-09-13 19:54:58.000000000 +0300
@@ -719,7 +719,7 @@ static struct boot_trace_ret ret;
int do_one_initcall(initcall_t fn)
{
int count = preempt_count();
- ktime_t calltime = {0}, delta, rettime;
+ ktime_t calltime, delta, rettime;

if (initcall_debug) {
call.caller = task_pid_nr(current);

Sa vedem daca o sa fie reparat. :)

De obicei dureaza cam 2 saptamani pana apar, cam asa am inteles. Bine, cele de securitate sunt reparate in maxim cateva ore.

Edited by Nytro
Link to comment
Share on other sites

[PATCH] drivers/block/cciss.c (2.6.34.7): Fixed useless compile warning

Cam la fel, un vector e initializat intr-un else, si in teorie poate fi folosit neinitializat, in practica nu se intampla asta, dar compilatorul nu are de unde sa stie asta. Doar o simpla initializare cu 0.

Nu vor mai aparea aceste avertismente urate:

drivers/block/cciss.c: In function ‘dev_show_unique_id’:
drivers/block/cciss.c:564:7: warning: ‘sn[0]’ may be used uninitialized in this function
drivers/block/cciss.c:564:7: warning: ‘sn[1]’ may be used uninitialized in this function
drivers/block/cciss.c:564:7: warning: ‘sn[2]’ may be used uninitialized in this function
drivers/block/cciss.c:564:7: warning: ‘sn[3]’ may be used uninitialized in this function
drivers/block/cciss.c:564:7: warning: ‘sn[4]’ may be used uninitialized in this function
drivers/block/cciss.c:564:7: warning: ‘sn[5]’ may be used uninitialized in this function
drivers/block/cciss.c:564:7: warning: ‘sn[6]’ may be used uninitialized in this function
drivers/block/cciss.c:564:7: warning: ‘sn[7]’ may be used uninitialized in this function
drivers/block/cciss.c:564:7: warning: ‘sn[8]’ may be used uninitialized in this function
drivers/block/cciss.c:564:7: warning: ‘sn[9]’ may be used uninitialized in this function
drivers/block/cciss.c:564:7: warning: ‘sn[10]’ may be used uninitialized in this function
drivers/block/cciss.c:564:7: warning: ‘sn[11]’ may be used uninitialized in this function
drivers/block/cciss.c:564:7: warning: ‘sn[12]’ may be used uninitialized in this function
drivers/block/cciss.c:564:7: warning: ‘sn[13]’ may be used uninitialized in this function
drivers/block/cciss.c:564:7: warning: ‘sn[14]’ may be used uninitialized in this function
drivers/block/cciss.c:564:7: warning: ‘sn[15]’ may be used uninitialized in this function

Patch:

--- a/drivers/block/cciss.c    2010-09-17 20:17:49.844010958 +0300
+++ b/drivers/block/cciss.c 2010-09-13 19:54:58.000000000 +0300
@@ -561,7 +561,7 @@ static ssize_t dev_show_unique_id(struct
{
drive_info_struct *drv = to_drv(dev);
struct ctlr_info *h = to_hba(drv->dev.parent);
+ __u8 sn[16];
- __u8 sn[16] = {0};
unsigned long flags;
int ret = 0;

Edit: Era inversat acesta, modificasem fisierul original sa vad daca mai apare eroare, si era inversat + cu -. :)

Edited by Nytro
Link to comment
Share on other sites

[PATCH] /drivers/acpi/acpica/nsrepair.c (2.6.34.7) - Fixed useless compile warning

Avertisment:

drivers/acpi/acpica/nsrepair.c: In function ‘acpi_ns_repair_object’:
drivers/acpi/acpica/nsrepair.c:125:29: warning: ‘new_object’ may be used uninitialized in this function

Patch:

--- a/drivers/acpi/acpica/nsrepair.c	2010-09-20 08:35:56.568006487 +0300
+++ b/drivers/acpi/acpica/nsrepair.c 2010-09-20 08:00:40.000000000 +0300
@@ -122,7 +122,7 @@ acpi_ns_repair_object(struct acpi_predef
union acpi_operand_object **return_object_ptr)
{
union acpi_operand_object *return_object = *return_object_ptr;
- union acpi_operand_object *new_object;
+ union acpi_operand_object *new_object = NULL;
acpi_status status;

ACPI_FUNCTION_NAME(ns_repair_object);

Edited by Nytro
Link to comment
Share on other sites

[PATCH] /arch/x86/kernel/apic/es7000_32.c (2.6.35.5): Unused variable

--- a/arch/x86/kernel/apic/es7000_32.c    2010-09-20 23:59:09.000000000 +0300
+++ b/arch/x86/kernel/apic/es7000_32.c 2010-09-26 13:08:06.261116776 +0300
@@ -129,8 +129,6 @@ int es7000_plat;
* GSI override for ES7000 platforms.
*/

-static unsigned int base;
-
static int __cpuinit wakeup_secondary_cpu_via_mip(int cpu, unsigned long eip)
{
unsigned long vect = 0, psaival = 0;

Warning:

arch/x86/kernel/apic/es7000_32.c:132: warning: ‘base’ defined but not used

Link to comment
Share on other sites

[PATCH] /fs/cifs/cifssmb.c (2.6.35.5): Simple pointer initialization

--- a/fs/cifs/cifssmb.c    2010-09-20 23:59:09.000000000 +0300
+++ b/fs/cifs/cifssmb.c 2010-09-26 13:05:45.281241095 +0300
@@ -3079,7 +3079,7 @@ CIFSSMBGetCIFSACL(const int xid, struct
__u32 parm_len;
__u32 acl_len;
struct smb_com_ntransact_rsp *pSMBr;
- char *pdata;
+ char *pdata = NULL;

/* validate_nttransact */
rc = validate_ntransact(iov[0].iov_base, (char **)&parm,

Warning:

fs/cifs/cifssmb.c: In function ‘CIFSSMBGetCIFSACL’:
fs/cifs/cifssmb.c:3082: warning: ‘pdata’ may be used uninitialized in this function

Link to comment
Share on other sites

[PATCH] /fs/fat/namei_vfat.c (2.6.35.5): Uninitialized variables

--- a/fs/fat/namei_vfat.c    2010-09-20 23:59:09.000000000 +0300
+++ b/fs/fat/namei_vfat.c 2010-09-26 15:36:39.604414996 +0300
@@ -587,12 +587,12 @@ static int vfat_build_slots(struct inode
struct fat_mount_options *opts = &sbi->options;
struct msdos_dir_slot *ps;
struct msdos_dir_entry *de;
- unsigned char cksum, lcase;
+ unsigned char cksum, lcase = 0;
unsigned char msdos_name[MSDOS_NAME];
wchar_t *uname;
__le16 time, date;
u8 time_cs;
- int err, ulen, usize, i;
+ int err, ulen = 0, usize, i;
loff_t offset;

*nr_slots = 0;

Warnings:

fs/fat/namei_vfat.c: In function ‘vfat_add_entry’:
fs/fat/namei_vfat.c:595: warning: ‘ulen’ may be used uninitialized in this function
fs/fat/namei_vfat.c:595: note: ‘ulen’ was declared here
fs/fat/namei_vfat.c:590: warning: ‘lcase’ may be used uninitialized in this function
fs/fat/namei_vfat.c:590: note: ‘lcase’ was declared here

Link to comment
Share on other sites

[PATCH] /fs/freevxfs/vxfs_lookup.c (2.6.35.5): Uninitialized pointer

--- a/fs/freevxfs/vxfs_lookup.c    2010-09-20 23:59:09.000000000 +0300
+++ b/fs/freevxfs/vxfs_lookup.c 2010-09-26 15:38:54.761538198 +0300
@@ -176,7 +176,7 @@ static ino_t
vxfs_inode_by_name(struct inode *dip, struct dentry *dp)
{
struct vxfs_direct *de;
- struct page *pp;
+ struct page *pp = NULL;
ino_t ino = 0;

de = vxfs_find_entry(dip, dp, &pp);

Warning:

fs/freevxfs/vxfs_lookup.c: In function ‘vxfs_lookup’:
fs/freevxfs/vxfs_lookup.c:179: warning: ‘pp’ may be used uninitialized in this function
fs/freevxfs/vxfs_lookup.c:179: note: ‘pp’ was declared here

Le-am luat la rand (dupa make allyesconfig - 2.6.35.5), astazi patru, m-am plictisit, poate mai fac maine vreo doua. :)

Link to comment
Share on other sites

[PATCH] /fs/ocfs2/slot_map.c (2.6.35.6): Uninitialized variable

--- a/fs/ocfs2/slot_map.c    2010-09-27 22:27:07.605568537 +0300
+++ b/fs/ocfs2/slot_map.c 2010-09-27 22:27:29.342567489 +0300
@@ -357,7 +357,7 @@ static int ocfs2_map_slot_buffers(struct
{
int status = 0;
u64 blkno;
- unsigned long long blocks, bytes;
+ unsigned long long blocks, bytes = 0;
unsigned int i;
struct buffer_head *bh;

Warning:

fs/ocfs2/slot_map.c: In function ‘ocfs2_init_slot_info’:
fs/ocfs2/slot_map.c:360: warning: ‘bytes’ may be used uninitialized in this function
fs/ocfs2/slot_map.c:360: note: ‘bytes’ was declared here

Link to comment
Share on other sites

[PATCH] /fs/omfs/file.c (2.6.35.6): Simple variable initialization

--- a/fs/omfs/file.c    2010-09-27 03:19:16.000000000 +0300
+++ b/fs/omfs/file.c 2010-09-27 22:36:44.800566930 +0300
@@ -222,7 +222,7 @@ static int omfs_get_block(struct inode *
struct buffer_head *bh;
sector_t next, offset;
int ret;
- u64 new_block;
+ u64 new_block = 0;
u32 max_extents;
int extent_count;
struct omfs_extent *oe;

Warning:

fs/omfs/file.c: In function ‘omfs_get_block’:
fs/omfs/file.c:225: warning: ‘new_block’ may be used uninitialized in this function

Link to comment
Share on other sites

[PATCH] /fs/qnx4/namei.c (2.6.35.6): Uninitialized variable warning

--- a/fs/qnx4/namei.c    2010-09-27 03:19:16.000000000 +0300
+++ b/fs/qnx4/namei.c 2010-09-27 22:40:39.249566930 +0300
@@ -101,7 +101,7 @@ static struct buffer_head *qnx4_find_ent

struct dentry * qnx4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
{
- int ino;
+ int ino = 0;
struct qnx4_inode_entry *de;
struct qnx4_link_info *lnk;
struct buffer_head *bh;

Warning:

fs/qnx4/namei.c: In function ‘qnx4_lookup’:
fs/qnx4/namei.c:104: warning: ‘ino’ may be used uninitialized in this function

Link to comment
Share on other sites

A trecut ceva timp de cand nu am mai facut ceva util, dar azi cand am incercat sa imi compilez ultima versiune stabila de kernel, 3.0.1 am primit mai multe avertismente la compilare:

drivers/edac/i82975x_edac.c: In function ‘i82975x_process_error_info’:
drivers/edac/i82975x_edac.c:298: warning: integer constant is too large for ‘unsigned long’ type

kernel/futex.c: In function ‘fixup_pi_state_owner’:
kernel/futex.c:1549: warning: ‘curval’ may be used uninitialized in this function
kernel/futex.c: In function ‘futex_lock_pi_atomic’:
kernel/futex.c:678: warning: ‘curval’ may be used uninitialized in this function
kernel/futex.c: In function ‘handle_futex_death’:
kernel/futex.c:2454: warning: ‘nval’ may be used uninitialized in this function

arch/x86/kernel/cpu/intel.c: In function ‘init_intel’:
arch/x86/kernel/cpu/intel.c:469: warning: too many arguments for format

drivers/scsi/lpfc/lpfc_debugfs.c: In function ‘T.1107’:
drivers/scsi/lpfc/lpfc_debugfs.c:411: warning: the frame size of 1048 bytes is larger than 1024 bytes

Cum aveam putin timp liber, am incercat sa ma fac util si sa fac niste patch-uri sa repar aceste probleme.

i82975x_edac.c

--- a/drivers/edac/i82975x_edac.c	2011-08-05 07:59:21.000000000 +0300
+++ b/drivers/edac/i82975x_edac.c 2011-08-07 15:11:33.292900211 +0300
@@ -278,7 +278,7 @@ static int i82975x_process_error_info(st
struct i82975x_error_info *info, int handle_errors)
{
int row, multi_chan, chan;
- unsigned long offst, page;
+ long long offst, page;

multi_chan = mci->csrows[0].nr_channels - 1;

@@ -295,7 +295,7 @@ static int i82975x_process_error_info(st

page = (unsigned long) info->eap;
if (info->xeap & 1)
- page |= 0x100000000ul;
+ page |= 0x100000000ll;
chan = page & 1;
page >>= 1;
offst = page & ((1 << PAGE_SHIFT) - 1);

futex.c

--- a/kernel/futex.c	2011-08-05 07:59:21.000000000 +0300
+++ b/kernel/futex.c 2011-08-07 14:45:26.117129011 +0300
@@ -675,7 +675,7 @@ static int futex_lock_pi_atomic(u32 __us
struct task_struct *task, int set_waiters)
{
int lock_taken, ret, ownerdied = 0;
- u32 uval, newval, curval, vpid = task_pid_vnr(task);
+ u32 uval, newval, uninitialized_var(curval), vpid = task_pid_vnr(task);

retry:
ret = lock_taken = 0;
@@ -1546,7 +1546,7 @@ static int fixup_pi_state_owner(u32 __us
u32 newtid = task_pid_vnr(newowner) | FUTEX_WAITERS;
struct futex_pi_state *pi_state = q->pi_state;
struct task_struct *oldowner = pi_state->owner;
- u32 uval, curval, newval;
+ u32 uval, uninitialized_var(curval), newval;
int ret;

/* Owner died? */
@@ -2451,7 +2451,7 @@ err_unlock:
*/
int handle_futex_death(u32 __user *uaddr, struct task_struct *curr, int pi)
{
- u32 uval, nval, mval;
+ u32 uval, uninitialized_var(nval), mval;

retry:
if (get_user(uval, uaddr))

intel.c

--- a/arch/x86/kernel/cpu/intel.c	2011-08-05 07:59:21.000000000 +0300
+++ b/arch/x86/kernel/cpu/intel.c 2011-08-07 14:58:03.532884828 +0300
@@ -466,7 +466,7 @@ static void __cpuinit init_intel(struct

rdmsrl(MSR_IA32_ENERGY_PERF_BIAS, epb);
if ((epb & 0xF) == 0) {
- printk_once(KERN_WARNING, "x86: updated energy_perf_bias"
+ printk_once(KERN_WARNING "%s", "x86: updated energy_perf_bias"
" to 'normal' from 'performance'\n"
"You can view and update epb via utility,"
" such as x86_energy_perf_policy(8)\n");

lpfc_debugfs.c

--- a/drivers/scsi/lpfc/lpfc_debugfs.c	2011-08-05 07:59:21.000000000 +0300
+++ b/drivers/scsi/lpfc/lpfc_debugfs.c 2011-08-07 15:45:48.007088993 +0300
@@ -378,7 +378,12 @@ lpfc_debugfs_dumpHBASlim_data(struct lpf
int len = 0;
int i, off;
uint32_t *ptr;
- char buffer[1024];
+ char *buffer = kmalloc(1024, GFP_KERNEL);
+
+ if(!buffer) {
+ printk(KERN_WARNING "lpfc_debugfs_dumpHBASlim_data: Unable to allocate memory\n");
+ return -ENOMEM;
+ }

off = 0;
spin_lock_irq(&phba->hbalock);
@@ -387,7 +392,7 @@ lpfc_debugfs_dumpHBASlim_data(struct lpf
lpfc_memcpy_from_slim(buffer,
phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);

- ptr = (uint32_t *)&buffer[0];
+ ptr = (uint32_t *)buffer;
off = lpfc_debugfs_last_hba_slim_off;

/* Set it up for the next time */
@@ -407,6 +412,7 @@ lpfc_debugfs_dumpHBASlim_data(struct lpf
}

spin_unlock_irq(&phba->hbalock);
+ kfree(buffer);
return len;
}

Stiu ca sunt mult mai multe avertismente la compilare, dar nu am avut timp de mai mult.

- La "i82975x_edac.c", se foloseste tipul "unsigned long" impreuna cu o constanta mai mare de 5 octeti. Cred ca depinde de sistem/compilator, dar cel putin la mine, sizeof(unsigned long) e 4, la fel si sizeof(unsigned long long) parca, dar sizeof(long long) este 8, destul pentru acea constanta si pentru acea variabila.

- La "futex.c", sunt folosite 3 variabile, in 3 functii diferite, insa acele variabile sunt initializate intr-un "if" (transmise prin referinta intr-o functie), deci compilatorul nu poate sigur ca vor fi folosite initializate si afiseaza un avertisment.

- La "intel.c", se foloseste incorect functia (de fapt macro-ul) printk_once. E la fel ca si printf, primul parametru e un sir in care se specifica formatul, sau un simplu sir de caractere, iar acolo nu e specificat formatul, care este necesar deoarece mai urmeaza un argument si se arunca un avertisment.

- La "lpfc_debugfs.c" e ceva mai complicat, se depaseste marimea maxima a stack frame-ului, problema care se rezolva prin alocarea dinamica a buffer-ului. Am facut si o mica verificare, daca alocarea s-a efectuat cu succes.

Daca voi avea timp, voi face mai multe... :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...