minigbm: consistent style
- Sometimes were return -1 and sometimes -errno. Prefer -errno
wherever possible.
- No braces for single line if/else statements. This does not
apply gralloc3/gralloc4, since that directory follows AOSP
style.
BUG=b:178495907
TEST=Cuttlefish CFI
Change-Id: I4c35768e015109730772a972b4b18e8d2c3cbb9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2665001
Reviewed-by: Gurchetan Singh <[email protected]>
Reviewed-by: Jason Macnak <[email protected]>
Commit-Queue: Gurchetan Singh <[email protected]>
Tested-by: Gurchetan Singh <[email protected]>
diff --git a/amdgpu.c b/amdgpu.c
index 46096f7..b2bd4db 100644
--- a/amdgpu.c
+++ b/amdgpu.c
@@ -337,12 +337,10 @@
return -ENODEV;
}
- if (sdma_init(priv, drv_get_fd(drv))) {
+ /* Continue on failure, as we can still succesfully map things without SDMA. */
+ if (sdma_init(priv, drv_get_fd(drv)))
drv_log("SDMA init failed\n");
- /* Continue, as we can still succesfully map things without SDMA. */
- }
-
metadata.tiling = TILE_TYPE_LINEAR;
metadata.priority = 1;
metadata.modifier = DRM_FORMAT_MOD_LINEAR;
@@ -650,9 +648,9 @@
static int amdgpu_unmap_bo(struct bo *bo, struct vma *vma)
{
- if (bo->priv)
+ if (bo->priv) {
return dri_bo_unmap(bo, vma);
- else {
+ } else {
int r = munmap(vma->addr, vma->length);
if (r)
return r;
diff --git a/cros_gralloc/cros_gralloc_buffer.cc b/cros_gralloc/cros_gralloc_buffer.cc
index 2982505..d13064b 100644
--- a/cros_gralloc/cros_gralloc_buffer.cc
+++ b/cros_gralloc/cros_gralloc_buffer.cc
@@ -128,9 +128,8 @@
return -EINVAL;
}
- if (lock_data_[0]) {
+ if (lock_data_[0])
return drv_bo_invalidate(bo_, lock_data_[0]);
- }
return 0;
}
@@ -142,9 +141,8 @@
return -EINVAL;
}
- if (lock_data_[0]) {
+ if (lock_data_[0])
return drv_bo_flush(bo_, lock_data_[0]);
- }
return 0;
}
diff --git a/cros_gralloc/cros_gralloc_driver.cc b/cros_gralloc/cros_gralloc_driver.cc
index 71fc8a9..b8eef71 100644
--- a/cros_gralloc/cros_gralloc_driver.cc
+++ b/cros_gralloc/cros_gralloc_driver.cc
@@ -39,9 +39,9 @@
return -1;
#endif
- if (fd == -1) {
+ if (fd == -1)
drv_log("Failed to create memfd '%s': %s.\n", name, strerror(errno));
- }
+
return fd;
}
@@ -132,9 +132,8 @@
std::string reserved_region_name = buffer_name + " reserved region";
int32_t reserved_region_fd = memfd_create_wrapper(reserved_region_name.c_str(), FD_CLOEXEC);
- if (reserved_region_fd == -1) {
- return -1;
- }
+ if (reserved_region_fd == -1)
+ return -errno;
if (ftruncate(reserved_region_fd, reserved_region_size)) {
drv_log("Failed to set reserved region size: %s.\n", strerror(errno));
@@ -521,7 +520,6 @@
{
std::lock_guard<std::mutex> lock(mutex_);
- for (const auto &pair : handles_) {
+ for (const auto &pair : handles_)
function(pair.first);
- }
}
diff --git a/cros_gralloc/gralloc3/CrosGralloc3Mapper.cc b/cros_gralloc/gralloc3/CrosGralloc3Mapper.cc
index b1082a0..08da016 100644
--- a/cros_gralloc/gralloc3/CrosGralloc3Mapper.cc
+++ b/cros_gralloc/gralloc3/CrosGralloc3Mapper.cc
@@ -461,7 +461,7 @@
std::string pixelFormatString = getPixelFormatString(pixelFormat);
drv_log("Failed to getResolvedDrmFormat. Failed to convert format %s\n",
pixelFormatString.c_str());
- return -1;
+ return -EINVAL;
}
uint64_t usage;
@@ -469,7 +469,7 @@
std::string usageString = getUsageString(bufferUsage);
drv_log("Failed to getResolvedDrmFormat. Failed to convert usage %s\n",
usageString.c_str());
- return -1;
+ return -EINVAL;
}
uint32_t resolvedDrmFormat = mDriver->get_resolved_drm_format(drmFormat, usage);
@@ -477,7 +477,7 @@
std::string drmFormatString = get_drm_format_string(drmFormat);
drv_log("Failed to getResolvedDrmFormat. Failed to resolve drm format %s\n",
drmFormatString.c_str());
- return -1;
+ return -EINVAL;
}
*outDrmFormat = resolvedDrmFormat;
diff --git a/cros_gralloc/gralloc3/CrosGralloc3Utils.cc b/cros_gralloc/gralloc3/CrosGralloc3Utils.cc
index 493fc1f..3f39305 100644
--- a/cros_gralloc/gralloc3/CrosGralloc3Utils.cc
+++ b/cros_gralloc/gralloc3/CrosGralloc3Utils.cc
@@ -330,17 +330,17 @@
if (descriptor.layerCount > 1) {
drv_log("Failed to convert descriptor. Unsupported layerCount: %d\n",
descriptor.layerCount);
- return -1;
+ return -EINVAL;
}
if (convertToDrmFormat(descriptor.format, &outCrosDescriptor->drm_format)) {
std::string pixelFormatString = getPixelFormatString(descriptor.format);
drv_log("Failed to convert descriptor. Unsupported format %s\n", pixelFormatString.c_str());
- return -1;
+ return -EINVAL;
}
if (convertToBufferUsage(descriptor.usage, &outCrosDescriptor->use_flags)) {
std::string usageString = getUsageString(descriptor.usage);
drv_log("Failed to convert descriptor. Unsupported usage flags %s\n", usageString.c_str());
- return -1;
+ return -EINVAL;
}
return 0;
}
diff --git a/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc b/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc
index b3a85b2..31b6cab 100644
--- a/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc
+++ b/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc
@@ -587,7 +587,7 @@
std::string pixelFormatString = getPixelFormatString(pixelFormat);
drv_log("Failed to getResolvedDrmFormat. Failed to convert format %s\n",
pixelFormatString.c_str());
- return -1;
+ return -EINVAL;
}
uint64_t usage;
@@ -595,7 +595,7 @@
std::string usageString = getUsageString(bufferUsage);
drv_log("Failed to getResolvedDrmFormat. Failed to convert usage %s\n",
usageString.c_str());
- return -1;
+ return -EINVAL;
}
uint32_t resolvedDrmFormat = mDriver->get_resolved_drm_format(drmFormat, usage);
@@ -603,7 +603,7 @@
std::string drmFormatString = get_drm_format_string(drmFormat);
drv_log("Failed to getResolvedDrmFormat. Failed to resolve drm format %s\n",
drmFormatString.c_str());
- return -1;
+ return -EINVAL;
}
*outDrmFormat = resolvedDrmFormat;
diff --git a/cros_gralloc/gralloc4/CrosGralloc4Utils.cc b/cros_gralloc/gralloc4/CrosGralloc4Utils.cc
index 5e37b7e..9bc27cb 100644
--- a/cros_gralloc/gralloc4/CrosGralloc4Utils.cc
+++ b/cros_gralloc/gralloc4/CrosGralloc4Utils.cc
@@ -321,17 +321,17 @@
if (descriptor.layerCount > 1) {
drv_log("Failed to convert descriptor. Unsupported layerCount: %d\n",
descriptor.layerCount);
- return -1;
+ return -EINVAL;
}
if (convertToDrmFormat(descriptor.format, &outCrosDescriptor->drm_format)) {
std::string pixelFormatString = getPixelFormatString(descriptor.format);
drv_log("Failed to convert descriptor. Unsupported format %s\n", pixelFormatString.c_str());
- return -1;
+ return -EINVAL;
}
if (convertToBufferUsage(descriptor.usage, &outCrosDescriptor->use_flags)) {
std::string usageString = getUsageString(descriptor.usage);
drv_log("Failed to convert descriptor. Unsupported usage flags %s\n", usageString.c_str());
- return -1;
+ return -EINVAL;
}
return 0;
}
@@ -663,7 +663,7 @@
const auto it = planeLayoutsMap.find(drmFormat);
if (it == planeLayoutsMap.end()) {
drv_log("Unknown plane layout for format %d\n", drmFormat);
- return -1;
+ return -EINVAL;
}
*outPlaneLayouts = it->second;
diff --git a/dri.c b/dri.c
index 3ee405b..ad4bf1e 100644
--- a/dri.c
+++ b/dri.c
@@ -94,17 +94,14 @@
if (dri->image_extension->queryImage(bo->priv, __DRI_IMAGE_ATTRIB_MODIFIER_UPPER,
&modifier_upper) &&
dri->image_extension->queryImage(bo->priv, __DRI_IMAGE_ATTRIB_MODIFIER_LOWER,
- &modifier_lower)) {
+ &modifier_lower))
bo->meta.format_modifier =
((uint64_t)modifier_upper << 32) | (uint32_t)modifier_lower;
- } else {
+ else
bo->meta.format_modifier = DRM_FORMAT_MOD_INVALID;
- }
- if (!dri->image_extension->queryImage(bo->priv, __DRI_IMAGE_ATTRIB_NUM_PLANES,
- &num_planes)) {
+ if (!dri->image_extension->queryImage(bo->priv, __DRI_IMAGE_ATTRIB_NUM_PLANES, &num_planes))
return -errno;
- }
bo->meta.num_planes = num_planes;
for (i = 0; i < num_planes; ++i) {
@@ -314,9 +311,8 @@
int ret, dri_format;
struct dri_driver *dri = bo->drv->priv;
- if (!dri->image_extension->createImageWithModifiers) {
+ if (!dri->image_extension->createImageWithModifiers)
return -ENOENT;
- }
dri_format = drm_format_to_dri_format(format);
diff --git a/drv.c b/drv.c
index 78e70d7..cb51887 100644
--- a/drv.c
+++ b/drv.c
@@ -438,9 +438,8 @@
/* No CPU access for protected buffers. */
assert(!(bo->meta.use_flags & BO_USE_PROTECTED));
- if (bo->is_test_buffer) {
+ if (bo->is_test_buffer)
return MAP_FAILED;
- }
mapping.rect = *rect;
mapping.refcount = 1;
@@ -603,9 +602,8 @@
int ret, fd;
assert(plane < bo->meta.num_planes);
- if (bo->is_test_buffer) {
+ if (bo->is_test_buffer)
return -EINVAL;
- }
ret = drmPrimeHandleToFD(bo->drv->fd, bo->handles[plane].u32, DRM_CLOEXEC | DRM_RDWR, &fd);
@@ -662,9 +660,8 @@
uint32_t count = 0;
size_t plane, p;
- if (bo->is_test_buffer) {
+ if (bo->is_test_buffer)
return 0;
- }
for (plane = 0; plane < bo->meta.num_planes; plane++) {
for (p = 0; p < plane; p++)
diff --git a/minigbm_helpers.c b/minigbm_helpers.c
index d58bbc9..781d675 100644
--- a/minigbm_helpers.c
+++ b/minigbm_helpers.c
@@ -62,7 +62,7 @@
dri_node_size = readlink(fd_path, dri_node, sizeof(dri_node));
if (dri_node_size < 0)
- return -1;
+ return -errno;
dri_node[dri_node_size] = '\0';
return dri_node_num(dri_node);
}
@@ -223,7 +223,7 @@
dir = opendir("/dev/dri");
if (!dir)
- return -1;
+ return -errno;
fd = -1;
while ((dir_ent = readdir(dir))) {
@@ -307,7 +307,7 @@
info->dri_node_num + 128);
fd = open(rendernode_name, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK);
if (fd < 0)
- return -1;
+ return -errno;
ret = detect_device_info(detect_flags, fd, info);
close(fd);
return ret;
diff --git a/minigbm_helpers.h b/minigbm_helpers.h
index 6264ac0..08e6283 100644
--- a/minigbm_helpers.h
+++ b/minigbm_helpers.h
@@ -10,12 +10,12 @@
extern "C" {
#endif
-#define GBM_DEV_TYPE_FLAG_DISCRETE (1u << 0) /* Discrete GPU. Separate chip, dedicated VRAM. */
-#define GBM_DEV_TYPE_FLAG_DISPLAY (1u << 1) /* Device capable of display. */
-#define GBM_DEV_TYPE_FLAG_3D (1u << 2) /* Device capable or 3D rendering. */
-#define GBM_DEV_TYPE_FLAG_ARMSOC (1u << 3) /* Device on ARM SOC. */
-#define GBM_DEV_TYPE_FLAG_USB (1u << 4) /* USB device, udl, evdi. */
-#define GBM_DEV_TYPE_FLAG_BLOCKED (1u << 5) /* Unsuitable device e.g. vgem, udl, evdi. */
+#define GBM_DEV_TYPE_FLAG_DISCRETE (1u << 0) /* Discrete GPU. Separate chip, dedicated VRAM. */
+#define GBM_DEV_TYPE_FLAG_DISPLAY (1u << 1) /* Device capable of display. */
+#define GBM_DEV_TYPE_FLAG_3D (1u << 2) /* Device capable or 3D rendering. */
+#define GBM_DEV_TYPE_FLAG_ARMSOC (1u << 3) /* Device on ARM SOC. */
+#define GBM_DEV_TYPE_FLAG_USB (1u << 4) /* USB device, udl, evdi. */
+#define GBM_DEV_TYPE_FLAG_BLOCKED (1u << 5) /* Unsuitable device e.g. vgem, udl, evdi. */
#define GBM_DEV_TYPE_FLAG_INTERNAL_LCD (1u << 6) /* Device is driving internal LCD. */
struct gbm_device_info {
diff --git a/rockchip.c b/rockchip.c
index 015c89e..5ae98f4 100644
--- a/rockchip.c
+++ b/rockchip.c
@@ -137,7 +137,7 @@
if (!drv_has_modifier(modifiers, count, DRM_FORMAT_MOD_LINEAR)) {
errno = EINVAL;
drv_log("no usable modifier found\n");
- return -1;
+ return -errno;
}
uint32_t stride;
diff --git a/virtio_gpu.c b/virtio_gpu.c
index 6e4625f..46f575d 100644
--- a/virtio_gpu.c
+++ b/virtio_gpu.c
@@ -113,9 +113,8 @@
uint32_t drm_format)
{
uint32_t virgl_format = translate_format(drm_format);
- if (!virgl_format) {
+ if (!virgl_format)
return false;
- }
uint32_t bitmask_index = virgl_format / 32;
uint32_t bit_index = virgl_format % 32;
@@ -311,24 +310,20 @@
{
struct virtio_gpu_priv *priv = (struct virtio_gpu_priv *)drv->priv;
- if (priv->caps.max_version == 0) {
+ if (priv->caps.max_version == 0)
return true;
- }
if ((use_flags & BO_USE_RENDERING) &&
- !virtio_gpu_bitmask_supports_format(&priv->caps.v1.render, drm_format)) {
+ !virtio_gpu_bitmask_supports_format(&priv->caps.v1.render, drm_format))
return false;
- }
if ((use_flags & BO_USE_TEXTURE) &&
- !virtio_gpu_bitmask_supports_format(&priv->caps.v1.sampler, drm_format)) {
+ !virtio_gpu_bitmask_supports_format(&priv->caps.v1.sampler, drm_format))
return false;
- }
if ((use_flags & BO_USE_SCANOUT) && priv->caps_is_v2 &&
- !virtio_gpu_bitmask_supports_format(&priv->caps.v2.scanout, drm_format)) {
+ !virtio_gpu_bitmask_supports_format(&priv->caps.v2.scanout, drm_format))
return false;
- }
return true;
}
@@ -343,17 +338,14 @@
struct virtio_gpu_priv *priv = (struct virtio_gpu_priv *)drv->priv;
// Only enable emulation on non-gbm virtio backends.
- if (priv->host_gbm_enabled) {
+ if (priv->host_gbm_enabled)
return false;
- }
- if (use_flags & (BO_USE_RENDERING | BO_USE_SCANOUT)) {
+ if (use_flags & (BO_USE_RENDERING | BO_USE_SCANOUT))
return false;
- }
- if (!virtio_gpu_supports_combination_natively(drv, DRM_FORMAT_R8, use_flags)) {
+ if (!virtio_gpu_supports_combination_natively(drv, DRM_FORMAT_R8, use_flags))
return false;
- }
return drm_format == DRM_FORMAT_NV12 || drm_format == DRM_FORMAT_NV21 ||
drm_format == DRM_FORMAT_YVU420 || drm_format == DRM_FORMAT_YVU420_ANDROID;
@@ -392,9 +384,8 @@
{
uint32_t i;
- for (i = 0; i < num_formats; i++) {
+ for (i = 0; i < num_formats; i++)
virtio_gpu_add_combination(drv, drm_formats[i], metadata, use_flags);
- }
}
static int virtio_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
@@ -461,13 +452,11 @@
* our platforms can display YV12, so we can treat as a SW buffer. Remove once
* this can be intelligently resolved in the guest. Also see gbm_bo_create.
*/
- if (format == DRM_FORMAT_YVU420_ANDROID) {
+ if (format == DRM_FORMAT_YVU420_ANDROID)
bind |= VIRGL_BIND_LINEAR;
- }
- if (use_flags) {
+ if (use_flags)
drv_log("Unhandled bo use flag: %llx\n", (unsigned long long)use_flags);
- }
return bind;
}
@@ -577,9 +566,8 @@
cap_args.size = sizeof(struct virgl_caps_v1);
ret = drmIoctl(drv->fd, DRM_IOCTL_VIRTGPU_GET_CAPS, &cap_args);
- if (ret) {
+ if (ret)
drv_log("DRM_IOCTL_VIRTGPU_GET_CAPS failed with %s\n", strerror(errno));
- }
}
return ret;
@@ -599,9 +587,8 @@
drv_log("DRM_IOCTL_VIRTGPU_GET_PARAM failed with %s\n", strerror(errno));
}
- if (features[feat_3d].enabled) {
+ if (features[feat_3d].enabled)
virtio_gpu_get_caps(drv, &priv->caps, &priv->caps_is_v2);
- }
// Multi-planar formats are currently only supported in virglrenderer through gbm.
priv->host_gbm_enabled =
@@ -819,11 +806,11 @@
// decoder flags don't differentiate between input and output buffers, but we can
// use the format to determine whether this buffer could be encoder/decoder output.
host_write_flags = BO_USE_RENDERING | BO_USE_CAMERA_WRITE;
- if (bo->meta.format == DRM_FORMAT_R8) {
+ if (bo->meta.format == DRM_FORMAT_R8)
host_write_flags |= BO_USE_HW_VIDEO_ENCODER;
- } else {
+ else
host_write_flags |= BO_USE_HW_VIDEO_DECODER;
- }
+
if ((bo->meta.use_flags & host_write_flags) == 0)
return 0;
@@ -853,9 +840,8 @@
// to avoid doing this for resources which don't rely on that transfer code,
// which is resources with the BO_USE_RENDERING flag set.
// TODO(b/145993887): Send also stride when the patches are landed
- if (priv->host_gbm_enabled) {
+ if (priv->host_gbm_enabled)
xfer.level = bo->meta.strides[0];
- }
}
if (virtio_gpu_supports_combination_natively(bo->drv, bo->meta.format,
@@ -933,9 +919,8 @@
// Unfortunately, the kernel doesn't actually pass the guest layer_stride and
// guest stride to the host (compare virtio_gpu.h and virtgpu_drm.h). We can use
// the level to work around this.
- if (priv->host_gbm_enabled) {
+ if (priv->host_gbm_enabled)
xfer.level = bo->meta.strides[0];
- }
if (virtio_gpu_supports_combination_natively(bo->drv, bo->meta.format,
bo->meta.use_flags)) {