Skip to content

Commit

Permalink
Merge pull request #198 from evelikov/warning-fixes
Browse files Browse the repository at this point in the history
Resolve "foo discards const qualifier" warnings et al.
  • Loading branch information
gregkh authored Sep 24, 2024
2 parents ab5f10c + a09ff9e commit df397a0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion desc-defs.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ static const struct desc desc_audio_3_ac_proc_unit_stereo_extender[] = {
};

/** UAC3: 4.5.2.10.3 Multi Func Proc Unit Descriptor; Algorithms; Table 4-41. */
static const char *uac3_proc_unit_multi_func_algorithms[] = {
static const char * const uac3_proc_unit_multi_func_algorithms[] = {
[0] = "Algorithm Undefined.",
[1] = "Beam Forming.",
[2] = "Acoustic Echo Cancellation.",
Expand Down
36 changes: 20 additions & 16 deletions lsusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static void dump_midistreaming_interface(libusb_device_handle *dev, const unsign
static void dump_videocontrol_interface(libusb_device_handle *dev, const unsigned char *buf, int protocol);
static void dump_videostreaming_interface(const unsigned char *buf);
static void dump_dfu_interface(const unsigned char *buf);
static char *dump_comm_descriptor(libusb_device_handle *dev, const unsigned char *buf, char *indent);
static void dump_comm_descriptor(libusb_device_handle *dev, const unsigned char *buf, const char *indent);
static void dump_hid_device(libusb_device_handle *dev, const struct libusb_interface_descriptor *interface, const unsigned char *buf);
static void dump_printer_device(libusb_device_handle *dev, const struct libusb_interface_descriptor *interface, const unsigned char *buf);
static void dump_audiostreaming_endpoint(libusb_device_handle *dev, const unsigned char *buf, int protocol);
Expand Down Expand Up @@ -684,7 +684,7 @@ static void dump_interface(libusb_device_handle *dev, const struct libusb_interf

static void dump_pipe_desc(const unsigned char *buf)
{
static const char *pipe_name[] = {
static const char * const pipe_name[] = {
"Reserved",
"Command pipe",
"Status pipe",
Expand Down Expand Up @@ -830,10 +830,15 @@ static void dump_endpoint(libusb_device_handle *dev, const struct libusb_interfa

static void dump_unit(unsigned int data, unsigned int len)
{
char *systems[5] = { "None", "SI Linear", "SI Rotation",
"English Linear", "English Rotation" };
static const char * const systems[5] = {
"None",
"SI Linear",
"SI Rotation",
"English Linear",
"English Rotation",
};

char *units[5][8] = {
static const char * const units[5][8] = {
{ "None", "None", "None", "None", "None",
"None", "None", "None" },
{ "None", "Centimeter", "Gram", "Seconds", "Kelvin",
Expand Down Expand Up @@ -2300,8 +2305,8 @@ static void dump_report_desc(unsigned char *b, int l)
{
unsigned int j, bsize, btag, btype, data = 0xffff, hut = 0xffff;
int i;
char *types[4] = { "Main", "Global", "Local", "reserved" };
char indent[] = " ";
static const char * const types[4] = { "Main", "Global", "Local", "reserved" };
static const char indent[] = " ";

printf(" Report Descriptor: (length is %d)\n", l);
for (i = 0; i < l; ) {
Expand Down Expand Up @@ -2538,12 +2543,12 @@ static void dump_hid_device(libusb_device_handle *dev,
}
}

static char *
dump_comm_descriptor(libusb_device_handle *dev, const unsigned char *buf, char *indent)
static void
dump_comm_descriptor(libusb_device_handle *dev, const unsigned char *buf, const char *indent)
{
int tmp;
char *str = NULL;
char *type;
const char *type;

switch (buf[2]) {
case 0:
Expand Down Expand Up @@ -2818,17 +2823,16 @@ dump_comm_descriptor(libusb_device_handle *dev, const unsigned char *buf, char *
/* FIXME there are about a dozen more descriptor types */
printf("%sUNRECOGNIZED CDC: ", indent);
dump_bytes(buf, buf[0]);
return "unrecognized comm descriptor";
return;
}

free(str);

return 0;
return;

bad:
printf("%sINVALID CDC (%s): ", indent, type);
dump_bytes(buf, buf[0]);
return "corrupt comm descriptor";
}

/* ---------------------------------------------------------------------- */
Expand All @@ -2840,7 +2844,7 @@ static void do_hub(libusb_device_handle *fd, unsigned tt_type, unsigned speed,
+ 2 /* bitmasks */ * HUB_STATUS_BYTELEN];
int i, ret, value;
unsigned int link_state;
const char * const link_state_descriptions[] = {
static const char * const link_state_descriptions[] = {
"U0",
"U1",
"U2",
Expand Down Expand Up @@ -3240,7 +3244,7 @@ static void dump_ssp_device_capability_desc(unsigned char *buf)
{
int i;
unsigned int bm_attr, ss_attr;
char bitrate_prefix[] = " KMG";
static const char bitrate_prefix[] = " KMG";

if (buf[0] < 12) {
fprintf(stderr, " Bad SuperSpeedPlus USB Device Capability descriptor.\n");
Expand Down Expand Up @@ -3294,7 +3298,7 @@ static void dump_container_id_device_capability_desc(unsigned char *buf)
static char *get_webusb_url(libusb_device_handle *fd, uint8_t vendor_req, uint8_t id)
{
unsigned char url_buf[255];
char *scheme;
const char *scheme;
char *url, *chr;
unsigned char i;
int ret;
Expand Down
1 change: 0 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ add_project_arguments(
'-Wno-unused-function',
'-Wno-deprecated-declarations',
# should be removed and the code fixed
'-Wno-discarded-qualifiers',
'-Wno-incompatible-pointer-types-discards-qualifiers',
'-Wno-missing-field-initializers',
]),
Expand Down
2 changes: 1 addition & 1 deletion sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int get_sysfs_name(char *buf, size_t size, libusb_device *dev)
return len;
}

int read_sysfs_prop(char *buf, size_t size, char *sysfs_name, char *propname)
int read_sysfs_prop(char *buf, size_t size, const char *sysfs_name, const char *propname)
{
int n, fd;
char path[PATH_MAX];
Expand Down
2 changes: 1 addition & 1 deletion sysfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/* ---------------------------------------------------------------------- */

int get_sysfs_name(char *buf, size_t size, libusb_device *dev);
extern int read_sysfs_prop(char *buf, size_t size, char *sysfs_name, char *propname);
extern int read_sysfs_prop(char *buf, size_t size, const char *sysfs_name, const char *propname);

/* ---------------------------------------------------------------------- */
#endif /* _SYSFS_H */

0 comments on commit df397a0

Please sign in to comment.