Skip to content

Commit 202751c

Browse files
committed
iio: adc: adrv9002: allocate struct adrv9002_fh_bin_table "on demand"
In the same spirit as ("iio: adc: adrv9002: fix multi device support for dpd"), allocate the needed space for writing the frequency hopping table on demand. The reasoning is that's not a fast patch and the interface is not even used unless frequency hopping is actually needed. Hence, let's save some space for the already huge device struct. Signed-off-by: Nuno Sa <nuno.sa@analog.com>
1 parent 88a0e3e commit 202751c

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

drivers/iio/adc/navassa/adrv9002.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4019,12 +4019,20 @@ static ssize_t adrv9002_profile_bin_read(struct file *filp, struct kobject *kobj
40194019
return memory_read_from_buffer(buf, count, &pos, phy->profile_buf, phy->profile_len);
40204020
}
40214021

4022+
struct adrv9002_fh_bin_table {
4023+
/*
4024+
* page size should be more than enough for a max of 64 entries!
4025+
* +1 so we the table can be properly NULL terminated.
4026+
*/
4027+
u8 bin_table[PAGE_SIZE + 1];
4028+
adi_adrv9001_FhHopFrame_t hop_tbl[ADI_ADRV9001_FH_MAX_HOP_TABLE_SIZE];
4029+
};
4030+
40224031
static ssize_t adrv9002_fh_bin_table_write(struct adrv9002_rf_phy *phy, char *buf, loff_t off,
40234032
size_t count, int hop, int table)
40244033
{
4025-
struct adrv9002_fh_bin_table *tbl = &phy->fh_table_bin_attr;
40264034
char *p, *line;
4027-
int entry = 0, ret, max_sz = ARRAY_SIZE(tbl->hop_tbl);
4035+
int entry = 0, ret, max_sz;
40284036

40294037
/* force a one write() call as it simplifies things a lot */
40304038
if (off) {
@@ -4043,10 +4051,15 @@ static ssize_t adrv9002_fh_bin_table_write(struct adrv9002_rf_phy *phy, char *bu
40434051
return -ENOTSUPP;
40444052
}
40454053

4054+
struct adrv9002_fh_bin_table *tbl __free(kfree) = kzalloc(sizeof(*tbl), GFP_KERNEL);
4055+
if (!tbl)
4056+
return -ENOMEM;
4057+
40464058
memcpy(tbl->bin_table, buf, count);
40474059
/* The bellow is always safe as @bin_table is bigger (by 1 byte) than the bin attribute */
40484060
tbl->bin_table[count] = '\0';
40494061

4062+
max_sz = ARRAY_SIZE(tbl->hop_tbl);
40504063
if (phy->fh.mode == ADI_ADRV9001_FHMODE_LO_RETUNE_REALTIME_PROCESS_DUAL_HOP)
40514064
max_sz /= 2;
40524065

drivers/iio/adc/navassa/adrv9002.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,6 @@ struct adrv9002_gpio {
218218
u32 signal;
219219
};
220220

221-
struct adrv9002_fh_bin_table {
222-
/*
223-
* page size should be more than enough for a max of 64 entries!
224-
* +1 so we the table can be properly NULL terminated.
225-
*/
226-
u8 bin_table[PAGE_SIZE + 1];
227-
adi_adrv9001_FhHopFrame_t hop_tbl[ADI_ADRV9001_FH_MAX_HOP_TABLE_SIZE];
228-
};
229-
230221
#define to_clk_priv(_hw) container_of(_hw, struct adrv9002_clock, hw)
231222

232223
struct adrv9002_chip_info {
@@ -274,7 +265,6 @@ struct adrv9002_rf_phy {
274265
char *bin_attr_buf;
275266
u8 *stream_buf;
276267
u16 stream_size;
277-
struct adrv9002_fh_bin_table fh_table_bin_attr;
278268
adi_adrv9001_FhCfg_t fh;
279269
struct adrv9002_rx_chan rx_channels[ADRV9002_CHANN_MAX];
280270
struct adrv9002_tx_chan tx_channels[ADRV9002_CHANN_MAX];

0 commit comments

Comments
 (0)