All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gero Schwäricke" <gero.schwaericke@sevenlab.de>
To: "Brigham Campbell" <me@brighamcampbell.com>,
	"Jean Delvare" <jdelvare@suse.de>, <linux-i2c@vger.kernel.org>
Cc: "Wolfram Sang" <wsa+renesas@sang-engineering.com>
Subject: Re: [PATCH v4 1/2] i2c-tools: Allow passing device file paths
Date: Mon, 13 Jul 2026 11:37:18 +0200	[thread overview]
Message-ID: <DJXCC2TLMKGV.GQPIOKMUNXD4@sevenlab.de> (raw)
In-Reply-To: <20260705-accept-device-path-v4-1-c62caa708a9e@brighamcampbell.com>

Hi Brigham,

On Mon Jul 6, 2026 at 6:27 AM CEST, Brigham Campbell wrote:
> @@ -446,6 +442,38 @@ int open_i2c_dev(int i2cbus, char *filename, size_t size, int quiet)
>  	return file;
>  }
>  
> +int open_i2c_dev_path(const char *i2cbus_arg, int quiet)
> +{
> +	int file = open(i2cbus_arg, O_RDWR);
> +
> +	if (file < 0 && !quiet) {
> +		fprintf(stderr, "Error: Could not open file "
> +			"`%s': %s\n", i2cbus_arg, strerror(errno));
> +		if (errno == EACCES)
> +			fprintf(stderr, "Run as root?\n");
> +	}
> +
> +	return file;
> +}
> +
> +int open_i2c_dev(char *i2cbus_arg, char **filename, size_t size, int quiet)
> +{
> +	int file, i2cbus;
> +
> +	i2cbus = lookup_i2c_bus(i2cbus_arg);
> +
> +	if (i2cbus < 0) {
> +		*filename = i2cbus_arg;
> +		file = open_i2c_dev_path(i2cbus_arg, quiet);
> +		if (file < 0)
> +			fprintf(stderr, "Failed to open `%s' as a bus name "
> +					"and as a path.\n", i2cbus_arg);
> +		return file;
> +	}
> +
> +	return open_i2c_dev_num(i2cbus, *filename, size, quiet);
> +}

It just occurred to me that the zero-copy pointer shuffling may be
overkill: I think using `char *filename`, instead of `char **filename`,
and copying `i2cbus_arg` in case it is a path reduces complexity at a
reasonably small cost of copying 20 bytes in the worst case. But it's a
matter of oppinion I assume.

Best,
Gero

-- 


sevenlab engineering GmbH <https://sevenlab.de>
serious engineering.

Geschäftsführer: Christian J. Pereira
Amtsgericht Köln, HRB 121730
Anschrift: Hansaring 20, 50670 Köln

  parent reply	other threads:[~2026-07-13  9:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-06  4:27 [PATCH v4 0/2] i2c-tools: Make tools accept bus path Brigham Campbell
2026-07-06  4:27 ` [PATCH v4 1/2] i2c-tools: Allow passing device file paths Brigham Campbell
2026-07-09 12:18   ` Wolfram Sang
2026-07-09 12:40   ` Gero Schwäricke
2026-07-11 19:24     ` Wolfram Sang
2026-07-13  9:23       ` Gero Schwäricke
2026-07-13 15:06         ` Wolfram Sang
2026-07-14  9:30           ` Gero Schwäricke
2026-07-14 10:13             ` Wolfram Sang
2026-07-13  9:37   ` Gero Schwäricke [this message]
2026-07-13 15:38     ` Brigham Campbell
2026-07-14  9:42       ` Gero Schwäricke
2026-07-06  4:27 ` [PATCH v4 2/2] i2c-tools: Document device paths as I2CBUS arg Brigham Campbell
2026-07-11 19:43   ` Wolfram Sang

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=DJXCC2TLMKGV.GQPIOKMUNXD4@sevenlab.de \
    --to=gero.schwaericke@sevenlab.de \
    --cc=jdelvare@suse.de \
    --cc=linux-i2c@vger.kernel.org \
    --cc=me@brighamcampbell.com \
    --cc=wsa+renesas@sang-engineering.com \
    /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.