diff --git a/plugins/nvme/fu-nvme-device.c b/plugins/nvme/fu-nvme-device.c index 2c9518385..234f5e01f 100644 --- a/plugins/nvme/fu-nvme-device.c +++ b/plugins/nvme/fu-nvme-device.c @@ -25,7 +25,6 @@ struct _FuNvmeDevice { FuUdevDevice parent_instance; - gchar *version_format; guint pci_depth; gint fd; guint64 write_block_size; @@ -186,13 +185,13 @@ static gboolean fu_nvme_device_set_version (FuNvmeDevice *self, const gchar *version, GError **error) { /* unset */ - if (self->version_format == NULL) { + if (fu_device_get_version_format (FU_DEVICE (self)) == FU_VERSION_FORMAT_UNKNOWN) { fu_device_set_version (FU_DEVICE (self), version); return TRUE; } /* AA.BB.CC.DD */ - if (g_strcmp0 (self->version_format, "quad") == 0) { + if (fu_device_get_version_format (FU_DEVICE (self)) == FU_VERSION_FORMAT_QUAD) { guint64 tmp = g_ascii_strtoull (version, NULL, 16); g_autofree gchar *version_new = NULL; if (tmp == 0 || tmp > G_MAXUINT32) { @@ -203,17 +202,16 @@ fu_nvme_device_set_version (FuNvmeDevice *self, const gchar *version, GError **e version); return FALSE; } - version_new = as_utils_version_from_uint32 (tmp, FU_VERSION_FORMAT_QUAD); + version_new = fu_common_version_from_uint32 (tmp, FU_VERSION_FORMAT_QUAD); fu_device_set_version (FU_DEVICE (self), version_new); return TRUE; } /* invalid, or not supported */ - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_INVALID_DATA, - "version format %s not recognised", - self->version_format); + g_set_error_literal (error, + G_IO_ERROR, + G_IO_ERROR_INVALID_DATA, + "version format not recognised"); return FALSE; } @@ -422,10 +420,6 @@ fu_nvme_device_set_quirk_kv (FuDevice *device, GError **error) { FuNvmeDevice *self = FU_NVME_DEVICE (device); - if (g_strcmp0 (key, "NvmeVersionFormat") == 0) { - self->version_format = g_strdup (value); - return TRUE; - } if (g_strcmp0 (key, "NvmeBlockSize") == 0) { self->write_block_size = fu_common_strtoull (value); return TRUE; @@ -451,8 +445,6 @@ fu_nvme_device_init (FuNvmeDevice *self) static void fu_nvme_device_finalize (GObject *object) { - FuNvmeDevice *self = FU_NVME_DEVICE (object); - g_free (self->version_format); G_OBJECT_CLASS (fu_nvme_device_parent_class)->finalize (object); } diff --git a/src/fu-device.c b/src/fu-device.c index 7e7bde909..b03dbfb9a 100644 --- a/src/fu-device.c +++ b/src/fu-device.c @@ -43,6 +43,7 @@ typedef struct { GPtrArray *children; guint remove_delay; /* ms */ FwupdStatus status; + FuVersionFormat version_format; guint progress; guint order; guint priority; @@ -676,6 +677,10 @@ fu_device_set_quirk_kv (FuDevice *self, fu_device_set_install_duration (self, fu_common_strtoull (value)); return TRUE; } + if (g_strcmp0 (key, FU_QUIRKS_VERSION_FORMAT) == 0) { + fu_device_set_version_format (self, fu_common_version_format_from_string (value)); + return TRUE; + } if (g_strcmp0 (key, FU_QUIRKS_CHILDREN) == 0) { g_auto(GStrv) sections = g_strsplit (value, ",", -1); for (guint i = 0; sections[i] != NULL; i++) { @@ -1351,6 +1356,43 @@ fu_device_set_status (FuDevice *self, FwupdStatus status) g_object_notify (G_OBJECT (self), "status"); } +/** + * fu_device_get_version_format: + * @self: A #FuDevice + * + * Returns how the device version should be formatted. + * + * Returns: the version format, e.g. %FU_VERSION_FORMAT_TRIPLET + * + * Since: 1.2.0 + **/ +FuVersionFormat +fu_device_get_version_format (FuDevice *self) +{ + FuDevicePrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (FU_IS_DEVICE (self), 0); + return priv->version_format; +} + +/** + * fu_device_set_version_format: + * @self: A #FuDevice + * @version_format: the version_format value, e.g. %FU_VERSION_FORMAT_TRIPLET + * + * Sets how the version should be formatted. + * + * Since: 1.2.0 + **/ +void +fu_device_set_version_format (FuDevice *self, FuVersionFormat version_format) +{ + FuDevicePrivate *priv = GET_PRIVATE (self); + g_return_if_fail (FU_IS_DEVICE (self)); + if (priv->version_format == version_format) + return; + priv->version_format = version_format; +} + /** * fu_device_get_progress: * @self: A #FuDevice diff --git a/src/fu-device.h b/src/fu-device.h index 3f421d41a..1b80db894 100644 --- a/src/fu-device.h +++ b/src/fu-device.h @@ -11,6 +11,7 @@ #include #include "fu-quirks.h" +#include "fu-common-version.h" G_BEGIN_DECLS @@ -176,6 +177,9 @@ void fu_device_set_remove_delay (FuDevice *self, FwupdStatus fu_device_get_status (FuDevice *self); void fu_device_set_status (FuDevice *self, FwupdStatus status); +FuVersionFormat fu_device_get_version_format (FuDevice *self); +void fu_device_set_version_format (FuDevice *self, + FuVersionFormat version_format); void fu_device_set_firmware_size_min (FuDevice *self, guint64 size_min); void fu_device_set_firmware_size_max (FuDevice *self, diff --git a/src/fu-quirks.h b/src/fu-quirks.h index c677de157..02d4947fd 100644 --- a/src/fu-quirks.h +++ b/src/fu-quirks.h @@ -242,6 +242,17 @@ gboolean fu_quirks_get_kvs_for_guid (FuQuirks *self, */ #define FU_QUIRKS_INSTALL_DURATION "InstallDuration" +/** + * FU_QUIRKS_VERSION_FORMAT: + * @key: the device ID, e.g. `HwId=USB\VID_0763&PID_2806` + * @value: the quirk format, e.g. `quad` + * + * Sets the version format the device should use for conversion. + * + * Since: 1.2.0 + */ +#define FU_QUIRKS_VERSION_FORMAT "VersionFormat" + G_END_DECLS #endif /* __FU_QUIRKS_H */