Skip to content

Commit

Permalink
gcc: drop const specifier from allocated string
Browse files Browse the repository at this point in the history
Use nornal (char*) for pointers we should free().
  • Loading branch information
Zdenek Kabelac committed Jun 3, 2024
1 parent 524df48 commit 76ca20a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
40 changes: 20 additions & 20 deletions lib/device/device_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,11 @@ static int _dm_uuid_has_prefix(char *sysbuf, const char *prefix)
}

/* the dm uuid uses the wwid of the underlying dev */
int dev_has_mpath_uuid(struct cmd_context *cmd, struct device *dev, const char **idname_out)
int dev_has_mpath_uuid(struct cmd_context *cmd, struct device *dev, char **idname_out)
{

char uuid[DM_UUID_LEN];
const char *idname;
char *idname;

if (!device_get_uuid(cmd, MAJOR(dev->dev), MINOR(dev->dev), uuid, sizeof(uuid)))
return_0;
Expand All @@ -526,10 +526,10 @@ int dev_has_mpath_uuid(struct cmd_context *cmd, struct device *dev, const char *
return 1;
}

static int _dev_has_crypt_uuid(struct cmd_context *cmd, struct device *dev, const char **idname_out)
static int _dev_has_crypt_uuid(struct cmd_context *cmd, struct device *dev, char **idname_out)
{
char uuid[DM_UUID_LEN];
const char *idname;
char *idname;

if (!device_get_uuid(cmd, MAJOR(dev->dev), MINOR(dev->dev), uuid, sizeof(uuid)))
return_0;
Expand All @@ -545,10 +545,10 @@ static int _dev_has_crypt_uuid(struct cmd_context *cmd, struct device *dev, cons
return 1;
}

static int _dev_has_lvmlv_uuid(struct cmd_context *cmd, struct device *dev, const char **idname_out)
static int _dev_has_lvmlv_uuid(struct cmd_context *cmd, struct device *dev, char **idname_out)
{
char uuid[DM_UUID_LEN];
const char *idname;
char *idname;

if (!device_get_uuid(cmd, MAJOR(dev->dev), MINOR(dev->dev), uuid, sizeof(uuid)))
return_0;
Expand Down Expand Up @@ -768,11 +768,11 @@ static int _dev_read_sys_serial(struct cmd_context *cmd, struct device *dev,
return 0;
}

const char *device_id_system_read(struct cmd_context *cmd, struct device *dev, uint16_t idtype)
char *device_id_system_read(struct cmd_context *cmd, struct device *dev, uint16_t idtype)
{
char sysbuf[PATH_MAX] = { 0 };
char sysbuf2[PATH_MAX] = { 0 };
const char *idname = NULL;
char *idname;
struct dev_wwid *dw;
unsigned i;

Expand Down Expand Up @@ -866,9 +866,9 @@ const char *device_id_system_read(struct cmd_context *cmd, struct device *dev, u
}

static int device_id_system_read_preferred(struct cmd_context *cmd, struct device *dev,
uint16_t *new_idtype, const char **new_idname)
uint16_t *new_idtype, char **new_idname)
{
const char *idname = NULL;
char *idname = NULL;
uint16_t idtype;

if (MAJOR(dev->dev) == cmd->dev_types->device_mapper_major) {
Expand Down Expand Up @@ -948,7 +948,7 @@ static int _dev_has_stable_id(struct cmd_context *cmd, struct device *dev)
{
char sysbuf[PATH_MAX] = { 0 };
struct dev_id *id;
const char *idname;
char *idname;

/*
* An idtype other than DEVNAME is stable, i.e. it doesn't change after
Expand Down Expand Up @@ -986,21 +986,21 @@ static int _dev_has_stable_id(struct cmd_context *cmd, struct device *dev)
if ((idname = device_id_system_read(cmd, dev, DEV_ID_TYPE_SYS_WWID))) {
/* see comment above */
if (!strstr(idname, "QEMU")) {
free((void*)idname);
free(idname);
return 1;
}
free((void*)idname);
free(idname);
return 0;
}

if ((idname = device_id_system_read(cmd, dev, DEV_ID_TYPE_SYS_SERIAL))) {
free((void*)idname);
free(idname);
return 1;
}

if ((MAJOR(dev->dev) == cmd->dev_types->loop_major) &&
(idname = device_id_system_read(cmd, dev, DEV_ID_TYPE_LOOP_FILE))) {
free((void*)idname);
free(idname);
return 1;
}

Expand Down Expand Up @@ -1912,8 +1912,8 @@ int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid_
{
char pvid[ID_LEN+1] = { 0 };
uint16_t idtype = 0;
const char *idname = NULL;
const char *check_idname = NULL;
char *idname = NULL;
char *check_idname = NULL;
const char *update_matching_kind = NULL;
const char *update_matching_name = NULL;
struct dev_use *du, *update_du = NULL, *du_dev, *du_pvid, *du_devname, *du_devid;
Expand Down Expand Up @@ -2129,7 +2129,7 @@ int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid_
if (!cmd->current_settings.yes &&
yes_no_prompt("Add device with duplicate PV to devices file?") == 'n') {
log_print_unless_silent("Device not added.");
free((void *)check_idname);
free(check_idname);
return 1;
}
}
Expand All @@ -2156,7 +2156,7 @@ int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid_
}
}

free((void *)check_idname);
free(check_idname);

if (!update_du) {
log_debug("Adding new entry to devices file for %s PVID %s %s %s.",
Expand Down Expand Up @@ -3958,7 +3958,7 @@ void device_ids_search(struct cmd_context *cmd, struct dm_list *new_devs,
new_devname = NULL;

if (cmd->device_ids_refresh_trigger || all_ids) {
if (!device_id_system_read_preferred(cmd, dev, &new_idtype, (const char **)&new_idname))
if (!device_id_system_read_preferred(cmd, dev, &new_idtype, &new_idname))
continue;
new_idname2 = strdup(new_idname);
new_devname = strdup(devname);
Expand Down
4 changes: 2 additions & 2 deletions lib/device/device_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void device_ids_check_serial(struct cmd_context *cmd, struct dm_list *scan_devs,
int noupdate, int *update_needed);
void device_ids_search(struct cmd_context *cmd, struct dm_list *new_devs,
int all_ids, int noupdate, int *update_needed);
const char *device_id_system_read(struct cmd_context *cmd, struct device *dev, uint16_t idtype);
char *device_id_system_read(struct cmd_context *cmd, struct device *dev, uint16_t idtype);
void device_id_update_vg_uuid(struct cmd_context *cmd, struct volume_group *vg, struct id *old_vg_id);
int device_ids_version_unchanged(struct cmd_context *cmd);

Expand All @@ -67,7 +67,7 @@ int read_sys_block(struct cmd_context *cmd, struct device *dev, const char *suff
int read_sys_block_binary(struct cmd_context *cmd, struct device *dev,
const char *suffix, char *sysbuf, int sysbufsize, int *retlen);

int dev_has_mpath_uuid(struct cmd_context *cmd, struct device *dev, const char **idname_out);
int dev_has_mpath_uuid(struct cmd_context *cmd, struct device *dev, char **idname_out);

int wwid_type_to_idtype(int wwid_type);
int idtype_to_wwid_type(int idtype);
Expand Down

0 comments on commit 76ca20a

Please sign in to comment.