linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: andy pugh <bodgesoc@gmail.com>
Cc: linux-gpio@vger.kernel.org
Subject: Re: [libgpiod] gpiod_line_get_value_bulk may be broken?
Date: Thu, 10 Aug 2023 08:46:07 +0800	[thread overview]
Message-ID: <ZNQzT2MtskTTZTiI@sol> (raw)
In-Reply-To: <CAN1+YZVD7ui4HSRMaGv+y-xT9NgeGNWDM_vx2MhZfiGrwhLPVA@mail.gmail.com>

On Thu, Aug 10, 2023 at 01:17:13AM +0100, andy pugh wrote:
> On Sun, 6 Aug 2023 at 10:29, Kent Gibson <warthog618@gmail.com> wrote:
> 
> > You can't statically link libgpiod until it is available as a package?
> 
> Would that mean merging the gpiod code into our codebase? Or can this
> be done some other way?
> 

There is no code movement at all, this is just telling the linker to
link libgpiod.a directly into your executable, rather than dynamically
linking against libgpiod.so.

The specifics of how to do that depend on your build.

Later, when libgpiod v2 becomes more widely available, you can switch
the build back to dynamic linkage.

> 
> Anyway, I now have it working, to an extent, but feel that there might
> be a problem with gpiod_line_request_bulk_input() and
> gpiod_line_request_bulk_output() if the bulk contains more than 5
> lines.
> 
> My current code is here (Work in progress!)
> 
> https://github.com/LinuxCNC/linuxcnc/blob/andypugh/hal_gpio/src/hal/drivers/hal_gpio.c
> 
> The test input file (
> https://github.com/LinuxCNC/linuxcnc/blob/andypugh/hal_gpio/src/test.hal
> ) attempts to configure 8 input and 8 output lines.
> However, if I change the 5 to 6 in either of lines 157 or 180 then the
> output looks something like:
> 
> HAL: initializing hal_lib
> /home/andypugh/linuxcnc-dev/bin/rtapi_app load hal_gpio
> inputs=GPIO5,GPIO6,GPIO12,GPIO13,GPIO16,GPIO17,GPIO18,GPIO19
> outputs=GPIO20,GPIO21,GPIO22,GPIO23,GPIO24,GPIO25,GPIO26,GPIO27
> HAL: initializing component 'halcmd9608'
> smalloc_dn: shmem available 1048284
> HAL: component 'halcmd9608' initialized, ID = 02
> Note: Using POSIX realtime
> before request
> rtapi_app: caught signal 11 - dumping core
> 
> The "before request" line was added for debugging, the "after request"
> line is never printed, nor is the error message if the request fails,
> so my belief is that lines 163 and/or 185 are segfaulting in the
> bulk_request functions.
> 
> The driver appears to work fine if I limit the number of parsed input
> strings to 5.

Check the sizes of the memory you are allocating.
e.g. this:

	    arr[c].chip = (struct gpiod_chip *)rtapi_kmalloc(sizeof(arr[c].chip), RTAPI_GFP_KERNEL);

allocates the space for a pointer to a struct, not the struct itself.
So you are corrupting your heap.

Try
	    arr[c].chip = (struct gpiod_chip *)rtapi_kmalloc(sizeof(*arr[c].chip), RTAPI_GFP_KERNEL);

Similarly your other mallocs.

Btw, v2 uses opaque structs so this wouldn't be an issue - it would do
the allocating for you, e.g. gpiod_chip_open() allocates and returns the
pointer to the struct gpiod_chip.

Cheers,
Kent.

  reply	other threads:[~2023-08-10  0:46 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-27 15:14 [libgpiod] gpiod_line_get_value_bulk may be broken? andy pugh
2023-07-27 20:53 ` Kent Gibson
2023-07-27 21:17   ` andy pugh
2023-07-27 21:55     ` Kent Gibson
2023-07-27 22:10       ` andy pugh
2023-07-27 22:36         ` Kent Gibson
2023-07-28  0:39       ` andy pugh
2023-07-28  1:07         ` andy pugh
2023-07-28  5:57         ` Kent Gibson
2023-07-28 19:01           ` andy pugh
2023-07-29  2:03             ` Kent Gibson
2023-08-05 22:55               ` andy pugh
2023-08-06  1:02                 ` Kent Gibson
2023-08-06  9:13                   ` andy pugh
2023-08-06  9:29                     ` Kent Gibson
2023-08-10  0:17                       ` andy pugh
2023-08-10  0:46                         ` Kent Gibson [this message]
2023-08-10 22:07                           ` andy pugh
2023-08-11  0:59                             ` Kent Gibson
2023-08-11  1:26                               ` andy pugh
2023-08-11  1:36                                 ` Kent Gibson
2023-08-14 22:25                                   ` How to use gpiod_line_set_flags andy pugh
2023-08-15  0:49                                     ` Kent Gibson
2023-08-15 18:03                                       ` andy pugh
2023-08-11 12:19               ` [libgpiod] gpiod_line_get_value_bulk may be broken? Bartosz Golaszewski

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=ZNQzT2MtskTTZTiI@sol \
    --to=warthog618@gmail.com \
    --cc=bodgesoc@gmail.com \
    --cc=linux-gpio@vger.kernel.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).