All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: Jerome Poncin <JPoncin@hilscher.com>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai] Hilscher driver for cifX boards
Date: Tue, 05 Mar 2013 12:26:31 +0100	[thread overview]
Message-ID: <5135D667.8060309@siemens.com> (raw)
In-Reply-To: <5135CCDE.5090401@hilscher.com>

On 2013-03-05 11:45, Jerome Poncin wrote:
> The code with #ifdef DEBUG is also questionable, it will tend to bitrot
> since nobody will think to enable it.
> 
> => I disagree with you, it could be helpful if somebody have a problem
> and want to debug quickly.
> But I can remove it if it's not standard to xenomai kernel.

#ifdef DEBUG is widely considered obsolete. If you have debug relevant
information, tracepoints are much better as they are runtime switchable.

But to look at a concrete example:

> +static ssize_t cifx_pci_read(struct rtdm_dev_context *context,
> +                 rtdm_user_info_t *user_info, void *buf,
> +                 size_t nbyte)
> +{
> +    struct rtdm_device *info = (struct rtdm_device *)context->device;
> +
> +    if (nbyte > sizeof(struct io_info)) {
> +#ifdef DEBUG
> +        rtdm_printk
> +            ("cifx rtdm driver error : data user size too big\n");
> +#endif /* DEBUG */
> +
> +        return 0;

If it is an error, return the proper code (-EINVAL? Or -E2BIG?). That
will be visible without any driver instrumentation.

> +    }
> +
> +    /* Copy data information for userland */
> +    if (rtdm_safe_copy_to_user(user_info, buf,
> +                   ((struct io_info *)info->device_data),
> +                   nbyte)) {
> +#ifdef DEBUG
> +        rtdm_printk
> +            ("cifx rtdm driver error : can't copy data from driver\n");
> +#endif /* DEBUG */

And this is a bug: return -EFAULT. Again, no need for driver
instrumentation.

> +    }
> +
> +    return nbyte;
> +}

...

> 
> I think you are not convinced yet that "code is the best documentation"
> 
> => Yes, you right it's because I worked long time on safety project (for
> me it's a habit) .
> Moreover I thunk it could be helpful in an open source project, if
> somebody want to more easily understand code.

Non-trivial code is better augmented with comments. However, commenting
on the obvious is like meaningless chatting. ;)

> 
> The coding style is a bit indigest
> 
> => I agree with you but that the price to be compliant with
> checkpatch.pl... limitation to 80 characters per line is difficult for me.
> If you saw some better thing to do, don't hesitate ;-) ! I tried to my
> best !

If you overrun the 80-char limit, it is usually a good sign that you
should introduce a function.

Jan

PS: Your mail client does funky marking of cited text. The web standard
is ">".

-- 
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux


  reply	other threads:[~2013-03-05 11:26 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-26  9:29 [Xenomai] Hilscher driver for cifX boards Jerome Poncin
2013-02-26 11:37 ` Jan Kiszka
2013-02-26 14:25   ` Jerome Poncin
2013-02-26 14:28     ` Jan Kiszka
2013-02-28  8:15       ` Jerome Poncin
2013-02-28 11:31         ` Jan Kiszka
2013-02-28 12:08           ` Jerome Poncin
2013-03-01 13:56             ` Jerome Poncin
2013-03-01 17:02               ` Jan Kiszka
2013-03-01 20:06               ` Gilles Chanteperdrix
2013-03-04  9:13               ` Jerome Poncin
2013-03-04 21:08                 ` Gilles Chanteperdrix
2013-03-05 10:45                   ` Jerome Poncin
2013-03-05 11:26                     ` Jan Kiszka [this message]
2013-03-05 12:21                       ` Gilles Chanteperdrix
2013-03-05 12:30                       ` Gilles Chanteperdrix
2013-03-05 15:42                       ` Jerome Poncin
2013-03-05 19:41                         ` Gilles Chanteperdrix
2013-03-06  8:10                           ` Jerome Poncin
2013-03-06  8:19                             ` Gilles Chanteperdrix
2013-03-06  8:55                               ` Jerome Poncin
2013-03-06 10:33                               ` Jerome Poncin
2013-03-06 12:04                                 ` Gilles Chanteperdrix
2013-03-06 13:58                                   ` Jerome Poncin
2013-03-06 15:28                                     ` Jan Kiszka
2013-03-06 21:05                                       ` Gilles Chanteperdrix
2013-03-07 15:33                                         ` Jerome Poncin
2013-03-08 10:17                                           ` Jerome Poncin
2013-03-08 12:22                                             ` Gilles Chanteperdrix
2013-03-12  9:10                                               ` Jerome Poncin
2013-03-12 12:21                                                 ` Gilles Chanteperdrix
2013-03-12 15:27                                                   ` Jerome Poncin
2013-03-12 19:38                                                     ` Gilles Chanteperdrix
2013-03-13 11:08                                                       ` Jerome Poncin
2013-03-15  9:09                                                         ` Jerome Poncin
2013-03-15 11:07                                                           ` Jan Kiszka
2013-03-15 13:04                                                             ` Jerome Poncin
2013-03-15 13:24                                                               ` Jan Kiszka
2013-03-18 10:02                                                                 ` Jerome Poncin
2013-03-19 13:42                                                                   ` Jerome Poncin
2013-03-06 20:42                                     ` Gilles Chanteperdrix
  -- strict thread matches above, loose matches on Subject: below --
2013-02-12 11:37 Stéphane LOS
2013-02-12 11:51 ` Jan Kiszka
2013-02-13 14:09   ` Stéphane LOS
2013-02-14 13:36     ` Stéphane LOS
2013-02-14 15:01       ` Stéphane LOS
2013-02-15 14:54         ` Jan Kiszka
2013-02-18 11:43           ` Stéphane LOS
2013-02-07 14:53 Stéphane LOS
2013-02-07 16:11 ` Gilles Chanteperdrix
2013-02-08  9:07   ` Stéphane LOS
2013-02-08  9:18     ` Gilles Chanteperdrix
2013-02-08 11:28       ` Jan Kiszka
2013-02-08 11:35         ` Gilles Chanteperdrix
2013-02-08 11:46           ` Jan Kiszka
     [not found]         ` <5114FD7B.20902@hilscher.com>
2013-02-08 13:40           ` Jan Kiszka
2013-02-08 14:33             ` Stéphane LOS

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=5135D667.8060309@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=JPoncin@hilscher.com \
    --cc=xenomai@xenomai.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.