Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
vm_tools: Fix some more lints
Browse files Browse the repository at this point in the history
Fix some misc lints in ~half the files in Sommelier:
* = default instead of {} on constructor/destructor
* Add missing override
* Use true instead of 1 if bool
* for (x : y) instead of (for int i = 0...)
* Func() instead of Func(void)
* Alphabetise includes
* Clean up include guards
* uint64_t instead of unsigned long long
* And a bonus 0 -> nullptr

BUG=b:280688827
TEST=CQ

Change-Id: Id9581ea8a616cd40b903efbb31278f77fee30233
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/4567774
Tested-by: David Munro <[email protected]>
Commit-Queue: David Munro <[email protected]>
Reviewed-by: Timothy Loh <[email protected]>
  • Loading branch information
David Munro authored and Chromeos LUCI committed May 30, 2023
1 parent c945fdd commit cf26b7f
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 41 deletions.
6 changes: 3 additions & 3 deletions sommelier-inpututils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "sommelier.h" // NOLINT(build/include_directory)
#include "sommelier-transform.h" // NOLINT(build/include_directory)
#include "sommelier-inpututils.h"
#include "sommelier.h" // NOLINT(build/include_directory)
#include "sommelier-inpututils.h" // NOLINT(build/include_directory)
#include "sommelier-transform.h" // NOLINT(build/include_directory)

#include <algorithm>
#include <assert.h>
Expand Down
6 changes: 3 additions & 3 deletions sommelier-inpututils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef VM_TOOLS_SOMMELIER_SOMMELIER_INPUTUTIL_H_
#define VM_TOOLS_SOMMELIER_SOMMELIER_INPUTUTIL_H_
#ifndef VM_TOOLS_SOMMELIER_SOMMELIER_INPUTUTILS_H_
#define VM_TOOLS_SOMMELIER_SOMMELIER_INPUTUTILS_H_

#include <sys/types.h>
#include <wayland-client.h>
Expand Down Expand Up @@ -48,4 +48,4 @@ void sl_touchrecorder_replay_to_listener(struct sl_touchrecorder* recorder,
void* data);
void sl_touchrecorder_purge_id(struct sl_touchrecorder* recorder, int32_t id);

#endif // VM_TOOLS_SOMMELIER_SOMMELIER_INPUTUTIL_H_
#endif // VM_TOOLS_SOMMELIER_SOMMELIER_INPUTUTILS_H_
2 changes: 1 addition & 1 deletion sommelier-seat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// found in the LICENSE file.

#include "sommelier.h" // NOLINT(build/include_directory)
#include "sommelier-transform.h" // NOLINT(build/include_directory)
#include "sommelier-inpututils.h" // NOLINT(build/include_directory)
#include "sommelier-stylus-tablet.h" // NOLINT(build/include_directory)
#include "sommelier-transform.h" // NOLINT(build/include_directory)

#include <assert.h>
#include <math.h>
Expand Down
8 changes: 4 additions & 4 deletions sommelier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3573,7 +3573,7 @@ int sl_run_parent(int argc,
rv = sigaction(SIGCHLD, &sa, nullptr);
errno_assert(rv >= 0);

do {
while (true) {
struct ucred ucred;
socklen_t length = sizeof(addr);

Expand Down Expand Up @@ -3635,7 +3635,7 @@ int sl_run_parent(int argc,
_exit(EXIT_FAILURE);
}
close(client_fd);
} while (1);
}

// Control should never reach here.
assert(false);
Expand Down Expand Up @@ -4127,7 +4127,7 @@ int real_main(int argc, char** argv) {

wl_client_add_destroy_listener(ctx.client, &client_destroy_listener);

do {
while (true) {
wl_display_flush_clients(ctx.host_display);
if (ctx.connection) {
if (ctx.needs_set_input_focus) {
Expand All @@ -4144,7 +4144,7 @@ int real_main(int argc, char** argv) {
if (errno != EINTR)
return EXIT_FAILURE;
}
} while (1);
}

return EXIT_SUCCESS;
} // NOLINT(readability/fn_size)
4 changes: 2 additions & 2 deletions testing/mock-wayland-channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using ::testing::PrintToString;
// Mock of Sommelier's Wayland connection to the host compositor.
class MockWaylandChannel : public WaylandChannel {
public:
MockWaylandChannel() {}
MockWaylandChannel() = default;

MOCK_METHOD(int32_t, init, (), (override));
MOCK_METHOD(bool, supports_dmabuf, (), (override));
Expand Down Expand Up @@ -67,7 +67,7 @@ class MockWaylandChannel : public WaylandChannel {
MOCK_METHOD(size_t, max_send_size, (), (override));

protected:
~MockWaylandChannel() override {}
~MockWaylandChannel() override = default;
};

// Match a WaylandSendReceive buffer containing exactly one Wayland message
Expand Down
2 changes: 1 addition & 1 deletion testing/x11-test-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class X11DirectScaleTest : public X11TestBase {
public:
void InitContext() override {
X11TestBase::InitContext();
ctx.use_direct_scale = 1;
ctx.use_direct_scale = true;
}

void Connect() override {
Expand Down
28 changes: 14 additions & 14 deletions virtualization/virtgpu_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

#include <errno.h>
#include <fcntl.h>
#include <gbm.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <xf86drm.h>
#include <gbm.h>

#include <cstdio>
#include <cstdlib>
#include <cstring>

#include "virtgpu_cross_domain_protocol.h" // NOLINT(build/include_directory)
#include "linux-headers/virtgpu_drm.h" // NOLINT(build/include_directory)
#include "virtgpu_cross_domain_protocol.h" // NOLINT(build/include_directory)
#include "wayland_channel.h" // NOLINT(build/include_directory)

// The size of a page for the guest kernel
Expand Down Expand Up @@ -150,11 +150,11 @@ int32_t VirtGpuChannel::init() {
PARAM(VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs),
};

for (uint32_t i = 0; i < REQUIRED_PARAMS_SIZE; i++) {
for (const auto& param : params) {
struct drm_virtgpu_getparam get_param = {0};

get_param.param = params[i].param;
get_param.value = (uint64_t)(uintptr_t)&params[i].value;
get_param.param = param.param;
get_param.value = (uint64_t)(uintptr_t)&param.value;
ret = drmIoctl(virtgpu_, DRM_IOCTL_VIRTGPU_GETPARAM, &get_param);
if (ret < 0) {
fprintf(stderr, "DRM_IOCTL_VIRTGPU_GET_PARAM failed with %s\n",
Expand All @@ -164,15 +164,15 @@ int32_t VirtGpuChannel::init() {
return -EINVAL;
}

if (params[i].param == VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs) {
if ((params[i].value & (1 << CAPSET_CROSS_DOMAIN)) == 0)
if (param.param == VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs) {
if ((param.value & (1 << CAPSET_CROSS_DOMAIN)) == 0)
return -ENOTSUP;
}
}

args.cap_set_id = CAPSET_CROSS_DOMAIN;
args.size = sizeof(struct CrossDomainCapabilities);
args.addr = (unsigned long long)&cross_domain_caps;
args.addr = (uint64_t)&cross_domain_caps;

ret = drmIoctl(virtgpu_, DRM_IOCTL_VIRTGPU_GET_CAPS, &args);
if (ret) {
Expand All @@ -195,7 +195,7 @@ int32_t VirtGpuChannel::init() {
return 0;
}

bool VirtGpuChannel::supports_dmabuf(void) {
bool VirtGpuChannel::supports_dmabuf() {
return supports_dmabuf_;
}

Expand All @@ -216,7 +216,7 @@ int32_t VirtGpuChannel::create_context(int& out_channel_fd) {
ctx_set_params[2].param = VIRTGPU_CONTEXT_PARAM_POLL_RINGS_MASK;
ctx_set_params[2].value = 1 << CROSS_DOMAIN_CHANNEL_RING;

init.ctx_set_params = (unsigned long long)&ctx_set_params[0];
init.ctx_set_params = (uint64_t)&ctx_set_params[0];
init.num_params = 3;
ret = drmIoctl(virtgpu_, DRM_IOCTL_VIRTGPU_CONTEXT_INIT, &init);
if (ret) {
Expand Down Expand Up @@ -248,8 +248,8 @@ int32_t VirtGpuChannel::create_context(int& out_channel_fd) {
return ret;
}

ring_addr_ = mmap(0, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, virtgpu_,
map.offset);
ring_addr_ = mmap(nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
virtgpu_, map.offset);

if (ring_addr_ == MAP_FAILED) {
fprintf(stderr, "mmap failed with %s\n", strerror(errno));
Expand Down Expand Up @@ -568,7 +568,7 @@ int32_t VirtGpuChannel::close_gem_handle(uint32_t gem_handle) {
return 0;
}

int32_t VirtGpuChannel::channel_poll(void) {
int32_t VirtGpuChannel::channel_poll() {
int32_t ret;
struct CrossDomainPoll cmd_poll = {{0}};

Expand Down Expand Up @@ -834,6 +834,6 @@ int32_t VirtGpuChannel::pipe_lookup(uint32_t identifier_type,
return -EINVAL;
}

size_t VirtGpuChannel::max_send_size(void) {
size_t VirtGpuChannel::max_send_size() {
return MAX_SEND_SIZE;
}
2 changes: 1 addition & 1 deletion virtualization/virtgpu_cross_domain_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@ struct CrossDomainReadWrite {
uint32_t pad;
};

#endif
#endif // VM_TOOLS_SOMMELIER_VIRTUALIZATION_VIRTGPU_CROSS_DOMAIN_PROTOCOL_H_
4 changes: 2 additions & 2 deletions virtualization/virtwl_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int32_t VirtWaylandChannel::init() {
return 0;
}

bool VirtWaylandChannel::supports_dmabuf(void) {
bool VirtWaylandChannel::supports_dmabuf() {
return supports_dmabuf_;
}

Expand Down Expand Up @@ -220,6 +220,6 @@ int32_t VirtWaylandChannel::handle_pipe(int read_fd,
return 0;
}

size_t VirtWaylandChannel::max_send_size(void) {
size_t VirtWaylandChannel::max_send_size() {
return MAX_SEND_SIZE;
}
20 changes: 10 additions & 10 deletions virtualization/wayland_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ struct WaylandBufferCreateOutput {

class WaylandChannel {
public:
WaylandChannel() {}
virtual ~WaylandChannel() {}
WaylandChannel() = default;
virtual ~WaylandChannel() = default;

// Initializes the Wayland Channel. Returns 0 on success, -errno on failure.
virtual int32_t init() = 0;

// Returns true if the Wayland channel supports dmabuf, false otherwise. If
// dmabuf is supported, Sommelier will use the `zwp_linux_dmabuf_v1`
// protocol.
virtual bool supports_dmabuf(void) = 0;
virtual bool supports_dmabuf() = 0;

// Creates a new context for handling the wayland command stream. Returns 0
// on success, and a pollable `out_channel_fd`. This fd represents the
Expand Down Expand Up @@ -159,13 +159,13 @@ class WaylandChannel {

// Returns the maximum size of opaque data that the channel is able to handle
// in the `send` function. Must be less than or equal to DEFAULT_BUFFER_SIZE.
virtual size_t max_send_size(void) = 0;
virtual size_t max_send_size() = 0;
};

class VirtWaylandChannel : public WaylandChannel {
public:
VirtWaylandChannel() : virtwl_{-1}, supports_dmabuf_(false) {}
~VirtWaylandChannel();
~VirtWaylandChannel() override;

int32_t init() override;
bool supports_dmabuf() override;
Expand All @@ -181,7 +181,7 @@ class VirtWaylandChannel : public WaylandChannel {

int32_t sync(int dmabuf_fd, uint64_t flags) override;
int32_t handle_pipe(int read_fd, bool readable, bool& hang_up) override;
size_t max_send_size(void) override;
size_t max_send_size() override;

private:
// virtwl device file descriptor
Expand All @@ -197,7 +197,7 @@ class VirtGpuChannel : public WaylandChannel {
ring_handle_{0},
supports_dmabuf_(false),
descriptor_id_{1} {}
~VirtGpuChannel();
~VirtGpuChannel() override;

int32_t init() override;
bool supports_dmabuf() override;
Expand All @@ -213,7 +213,7 @@ class VirtGpuChannel : public WaylandChannel {

int32_t sync(int dmabuf_fd, uint64_t flags) override;
int32_t handle_pipe(int read_fd, bool readable, bool& hang_up) override;
size_t max_send_size(void) override;
size_t max_send_size() override;

private:
/*
Expand Down Expand Up @@ -246,7 +246,7 @@ class VirtGpuChannel : public WaylandChannel {
uint32_t size,
uint32_t ring_idx,
bool wait);
int32_t channel_poll(void);
int32_t channel_poll();
int32_t close_gem_handle(uint32_t gem_handle);
int32_t create_host_blob(uint64_t blob_id, uint64_t size, int& out_fd);

Expand All @@ -265,7 +265,7 @@ class VirtGpuChannel : public WaylandChannel {
struct WaylandSendReceive& receive,
int& out_read_pipe);

int32_t handle_read(void);
int32_t handle_read();

int32_t pipe_lookup(uint32_t identifier_type,
uint32_t& identifier,
Expand Down

0 comments on commit cf26b7f

Please sign in to comment.