From 405addf37318c8b603b99e26f1b4a0dfaecc74bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nuno=20S=C3=A1?= <nuno.sa@analog.com>
Date: Fri, 25 Jun 2021 11:49:37 +0200
Subject: [PATCH] examples: adrv9009-iiostream: fix variable shadowing warnings
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The IIO context is defined as a global variable so that it does not make
sense to pass it around local functions. Moreover, this was triggering
-Wshadow.

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
 examples/adrv9009-iiostream.c | 36 +++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/examples/adrv9009-iiostream.c b/examples/adrv9009-iiostream.c
index 7cf13db3c..07c8ad36a 100644
--- a/examples/adrv9009-iiostream.c
+++ b/examples/adrv9009-iiostream.c
@@ -129,7 +129,7 @@ static char* get_ch_name(const char* type, int id)
 }
 
 /* returns adrv9009 phy device */
-static struct iio_device* get_adrv9009_phy(struct iio_context *ctx)
+static struct iio_device* get_adrv9009_phy(void)
 {
 	struct iio_device *dev =  iio_context_find_device(ctx, "adrv9009-phy");
 	IIO_ENSURE(dev && "No adrv9009-phy found");
@@ -137,7 +137,7 @@ static struct iio_device* get_adrv9009_phy(struct iio_context *ctx)
 }
 
 /* finds adrv9009 streaming IIO devices */
-static bool get_adrv9009_stream_dev(struct iio_context *ctx, enum iodev d, struct iio_device **dev)
+static bool get_adrv9009_stream_dev(enum iodev d, struct iio_device **dev)
 {
 	switch (d) {
 	case TX: *dev = iio_context_find_device(ctx, "axi-adrv9009-tx-hpc"); return *dev != NULL;
@@ -147,7 +147,7 @@ static bool get_adrv9009_stream_dev(struct iio_context *ctx, enum iodev d, struc
 }
 
 /* finds adrv9009 streaming IIO channels */
-static bool get_adrv9009_stream_ch(__notused struct iio_context *ctx, enum iodev d, struct iio_device *dev, int chid, char modify, struct iio_channel **chn)
+static bool get_adrv9009_stream_ch(enum iodev d, struct iio_device *dev, int chid, char modify, struct iio_channel **chn)
 {
 	*chn = iio_device_find_channel(dev, modify ? get_ch_name_mod("voltage", chid, modify) : get_ch_name("voltage", chid), d == TX);
 	if (!*chn)
@@ -156,37 +156,37 @@ static bool get_adrv9009_stream_ch(__notused struct iio_context *ctx, enum iodev
 }
 
 /* finds adrv9009 phy IIO configuration channel with id chid */
-static bool get_phy_chan(struct iio_context *ctx, enum iodev d, int chid, struct iio_channel **chn)
+static bool get_phy_chan(enum iodev d, int chid, struct iio_channel **chn)
 {
 	switch (d) {
-	case RX: *chn = iio_device_find_channel(get_adrv9009_phy(ctx), get_ch_name("voltage", chid), false); return *chn != NULL;
-	case TX: *chn = iio_device_find_channel(get_adrv9009_phy(ctx), get_ch_name("voltage", chid), true);  return *chn != NULL;
+	case RX: *chn = iio_device_find_channel(get_adrv9009_phy(), get_ch_name("voltage", chid), false); return *chn != NULL;
+	case TX: *chn = iio_device_find_channel(get_adrv9009_phy(), get_ch_name("voltage", chid), true);  return *chn != NULL;
 	default: IIO_ENSURE(0); return false;
 	}
 }
 
 /* finds adrv9009 local oscillator IIO configuration channels */
-static bool get_lo_chan(struct iio_context *ctx, struct iio_channel **chn)
+static bool get_lo_chan(struct iio_channel **chn)
 {
 	 // LO chan is always output, i.e. true
-	*chn = iio_device_find_channel(get_adrv9009_phy(ctx), get_ch_name("altvoltage", 0), true); return *chn != NULL;
+	*chn = iio_device_find_channel(get_adrv9009_phy(), get_ch_name("altvoltage", 0), true); return *chn != NULL;
 }
 
 /* applies streaming configuration through IIO */
-bool cfg_adrv9009_streaming_ch(struct iio_context *ctx, struct stream_cfg *cfg, int chid)
+bool cfg_adrv9009_streaming_ch(struct stream_cfg *cfg, int chid)
 {
 	struct iio_channel *chn = NULL;
 
 	// Configure phy and lo channels
 	printf("* Acquiring ADRV9009 phy channel %d\n", chid);
-	if (!get_phy_chan(ctx, true, chid, &chn)) {	return false; }
+	if (!get_phy_chan(true, chid, &chn)) {	return false; }
 
 	rd_ch_lli(chn, "rf_bandwidth");
 	rd_ch_lli(chn, "sampling_frequency");
 
 	// Configure LO channel
 	printf("* Acquiring ADRV9009 TRX lo channel\n");
-	if (!get_lo_chan(ctx, &chn)) { return false; }
+	if (!get_lo_chan(&chn)) { return false; }
 	wr_ch_lli(chn, "frequency", cfg->lo_hz);
 	return true;
 }
@@ -216,17 +216,17 @@ int main (__notused int argc, __notused char **argv)
 	IIO_ENSURE(iio_context_get_devices_count(ctx) > 0 && "No devices");
 
 	printf("* Acquiring ADRV9009 streaming devices\n");
-	IIO_ENSURE(get_adrv9009_stream_dev(ctx, TX, &tx) && "No tx dev found");
-	IIO_ENSURE(get_adrv9009_stream_dev(ctx, RX, &rx) && "No rx dev found");
+	IIO_ENSURE(get_adrv9009_stream_dev(TX, &tx) && "No tx dev found");
+	IIO_ENSURE(get_adrv9009_stream_dev(RX, &rx) && "No rx dev found");
 
 	printf("* Configuring ADRV9009 for streaming\n");
-	IIO_ENSURE(cfg_adrv9009_streaming_ch(ctx, &trxcfg, 0) && "TRX device not found");
+	IIO_ENSURE(cfg_adrv9009_streaming_ch(&trxcfg, 0) && "TRX device not found");
 
 	printf("* Initializing ADRV9009 IIO streaming channels\n");
-	IIO_ENSURE(get_adrv9009_stream_ch(ctx, RX, rx, 0, 'i', &rx0_i) && "RX chan i not found");
-	IIO_ENSURE(get_adrv9009_stream_ch(ctx, RX, rx, 0, 'q', &rx0_q) && "RX chan q not found");
-	IIO_ENSURE(get_adrv9009_stream_ch(ctx, TX, tx, 0, 0, &tx0_i) && "TX chan i not found");
-	IIO_ENSURE(get_adrv9009_stream_ch(ctx, TX, tx, 1, 0, &tx0_q) && "TX chan q not found");
+	IIO_ENSURE(get_adrv9009_stream_ch(RX, rx, 0, 'i', &rx0_i) && "RX chan i not found");
+	IIO_ENSURE(get_adrv9009_stream_ch(RX, rx, 0, 'q', &rx0_q) && "RX chan q not found");
+	IIO_ENSURE(get_adrv9009_stream_ch(TX, tx, 0, 0, &tx0_i) && "TX chan i not found");
+	IIO_ENSURE(get_adrv9009_stream_ch(TX, tx, 1, 0, &tx0_q) && "TX chan q not found");
 
 	printf("* Enabling IIO streaming channels\n");
 	iio_channel_enable(rx0_i);