Re: KernelNewbies Wikki

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/1/05, Sanjay Kumar, Noida <sanjayku@xxxxxxxxxxx> wrote:

> Hi,

> if the kmalloc fails for hello_msg, why do we need to release
> the semaphore.This is the code snippet:
>         if (!hello_msg){
>                 up(&hello_sem);
>                 return -ENOMEM;
>         }

Please read the code carefully again:

static ssize_t hello_write(struct inode *inode, const char __user
*user_buf, size_t len, loff_t offset)
{
        ..
        down(&hello_sem);   --> semaphore initialized here.
        if (hello_msg) {
                kfree(hello_msg);
                hello_msg = kmalloc(len+1, GFP_KERNEL);
                if (!hello_msg) {
                        up(&hello_sem);  --> if fails,  change back to
original semval and return
                        return -ENOMEM;

..
}

Where is the problem?

./h
www.embedded-tutorials.com - Embedded Linux Tutorials

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux