kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: greg@kroah.com (Greg KH)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Simple Read operation on a misc device driver
Date: Fri, 18 Apr 2014 14:35:53 -0700	[thread overview]
Message-ID: <20140418213553.GA3211@kroah.com> (raw)
In-Reply-To: <CAJ8pNUPDVN+C1Up_JYGGG6WbPnZV0A63a7VN8hqHPSG3heOj3w@mail.gmail.com>

On Fri, Apr 18, 2014 at 06:30:44PM -0300, Aldo Esteban Paz wrote:
> For the Eudyptula's Chanllenge Task 6, i need to write a misc device
> driver with simple read/write operations.
>  The following was the answer to part of my code:
> 
> > static char eid[] = EUDYPTULAID;
> >
> > static ssize_t misc_device_read(struct file *file, char __user *buf,
> >                                         size_t count, loff_t *ppos)
> > {
> >         if (*ppos == sizeof(eid))
> >                 return 0;
> >         else
> >                 if (*ppos != 0 || count < sizeof(eid))
> >                         return -EINVAL;
> >
> >         if (copy_to_user(buf, eid, sizeof(eid)))
> >                 return -EINVAL;
> >
> >         *ppos = sizeof(eid);
> >
> >         return *ppos;
> > }
> 
> This whole function can be made much more "simple" and reduced to one
> single line {hint} (It's just a "simple" function call {hint}).
> 
> Anyone know that "single" function?

Yes, but you really should do your own research for stuff like this,
that's what the challenge is all about, not asking others to do it for
you :(

  reply	other threads:[~2014-04-18 21:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-18 21:30 Simple Read operation on a misc device driver Aldo Esteban Paz
2014-04-18 21:35 ` Greg KH [this message]
2014-04-19 16:44   ` L. Alberto Giménez
2014-04-19 18:18     ` Fernando Apesteguía

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140418213553.GA3211@kroah.com \
    --to=greg@kroah.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).