Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.misc > #8182

Re: An interrupt handler can call function sprintf()?

From Jerry Peters <jerry@example.invalid>
Newsgroups comp.os.linux.misc
Subject Re: An interrupt handler can call function sprintf()?
Date 2013-05-19 20:38 +0000
Organization A noiseless patient Spider
Message-ID <knbd90$qbd$1@dont-email.me> (permalink)
References <6c25f801-621d-4484-a3b2-f5cc4491a4a6@googlegroups.com>

Show all headers | View raw


fl <rxjwg98@gmail.com> wrote:
> Hi,
> 
> I remember it said that C lib function printf() cannot be called in a device driver in Linux. Today I come across the following code snippet. I wonder that sprintf function can be called in the interrupt function?
> 
It can't, because it writes to a file, stdout. Sprintf "writes" to an
existing string so there's no i/o. Sprintf is just a convenient way to
construct a fancy formatted string.

There is another function, kprintf, which can be used similiarly to
printf, but it wrties to a kernel buffer.

	Jerry

> Interrupt function is part of device driver or not?
> 
> Please clarify those concepts if you can. Thanks.
> 
> 
> 
> 
> 
> 
> ......
> irqreturn_t short_interrupt(int irq, void *dev_id, struct pt_regs *regs)
> {
>  struct timeval tv; 
>  int written;
> 
>  do_gettimeofday(&tv);
> /* Write a 16 byte record. Assume PAGE_SIZE is a multiple of 16 */
>  written = sprintf((char *)short_head,"%08u.%06u\n",
>            (int)(tv.tv_sec % 100000000), (int)(tv.tv_usec));
>  BUG_ON(written != 16);
>  short_incr_bp(&short_head, written);
>  wake_up_interruptible(&short_queue); /* awake any reading process */
>  return IRQ_HANDLED;
> }

Back to comp.os.linux.misc | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

An interrupt handler can call function sprintf()? fl <rxjwg98@gmail.com> - 2013-05-19 10:11 -0700
  Re: An interrupt handler can call function sprintf()? Jerry Peters <jerry@example.invalid> - 2013-05-19 20:38 +0000
    Re: An interrupt handler can call function sprintf()? Jerry Peters <jerry@example.invalid> - 2013-05-19 20:58 +0000

csiph-web