Skip to content

Commit

Permalink
BACKPORT: ipts: Cleanup ipts-companion to pass checkpatch
Browse files Browse the repository at this point in the history
Signed-off-by: Dorian Stoll <dorian.stoll@tmsp.io>

(cherry-picked from commit f63f758)
  • Loading branch information
StollD authored and kitakar5525 committed Jan 19, 2020
1 parent 36bb00d commit 6c2bceb
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 32 deletions.
81 changes: 51 additions & 30 deletions drivers/misc/ipts/ipts-companion.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
*
* Intel Precise Touch & Stylus
* Copyright (c) 2016 Intel Corporation
*
*/

#include <linux/firmware.h>
#include <linux/ipts.h>
#include <linux/ipts-binary.h>
Expand All @@ -11,17 +19,19 @@
#define IPTS_FW_PATH_FMT "intel/ipts/%s"
#define IPTS_FW_CONFIG_FILE "ipts_fw_config.bin"

ipts_companion_t *ipts_companion;
struct ipts_companion *ipts_companion;
DEFINE_MUTEX(ipts_companion_lock);

bool ipts_companion_available(void)
{
bool ret;

mutex_lock(&ipts_companion_lock);

ret = ipts_companion != NULL;

mutex_unlock(&ipts_companion_lock);

return ret;
}

Expand All @@ -33,9 +43,11 @@ bool ipts_companion_available(void)
* with a fallback in case a companion driver cannot be found.
*/

int ipts_add_companion(ipts_companion_t *companion)
int ipts_add_companion(struct ipts_companion *companion)
{
int ret;

// Make sure that access to the companion is synchronized
mutex_lock(&ipts_companion_lock);

if (ipts_companion == NULL) {
Expand All @@ -46,13 +58,16 @@ int ipts_add_companion(ipts_companion_t *companion)
}

mutex_unlock(&ipts_companion_lock);

return ret;
}
EXPORT_SYMBOL_GPL(ipts_add_companion);

int ipts_remove_companion(ipts_companion_t *companion)
int ipts_remove_companion(struct ipts_companion *companion)
{
int ret;

// Make sure that access to the companion is synchronized
mutex_lock(&ipts_companion_lock);

if (ipts_companion != NULL && companion != NULL &&
Expand All @@ -75,22 +90,23 @@ EXPORT_SYMBOL_GPL(ipts_remove_companion);
*/

int ipts_request_firmware(const struct firmware **fw, const char *name,
struct device *device)
struct device *device)
{
int ret = 0;
char fw_path[MAX_IOCL_FILE_PATH_LEN];

// Make sure that access to the companion is synchronized
mutex_lock(&ipts_companion_lock);

// Check if a companion was registered. If not, skip
// forward and try to load the firmware from the legacy path
if (ipts_companion == NULL || ipts_modparams.ignore_companion) {
if (ipts_companion == NULL || ipts_modparams.ignore_companion)
goto request_firmware_fallback;
}

ret = ipts_companion->firmware_request(ipts_companion, fw, name, device);
if (!ret) {
ret = ipts_companion->firmware_request(ipts_companion, fw,
name, device);
if (!ret)
goto request_firmware_return;
}

request_firmware_fallback:

Expand All @@ -108,49 +124,57 @@ int ipts_request_firmware(const struct firmware **fw, const char *name,
request_firmware_return:

mutex_unlock(&ipts_companion_lock);

return ret;
}

static ipts_bin_fw_list_t *ipts_alloc_fw_list(ipts_bin_fw_info_t **fw)
static struct ipts_bin_fw_list *ipts_alloc_fw_list(
struct ipts_bin_fw_info **fw)
{
int size, len, i, j;
ipts_bin_fw_list_t *fw_list;
struct ipts_bin_fw_list *fw_list;
char *itr;

// Figure out the amount of firmware files inside of the array
len = 0;
while (fw[len] != NULL) {
while (fw[len] != NULL)
len++;
}

// Determine the size that the final list will need in memory
size = sizeof(ipts_bin_fw_list_t);
size = sizeof(struct ipts_bin_fw_list);
for (i = 0; i < len; i++) {
size += sizeof(ipts_bin_fw_info_t);
size += sizeof(ipts_bin_data_file_info_t) *
fw[i]->num_of_data_files;
size += sizeof(struct ipts_bin_fw_info);
size += sizeof(struct ipts_bin_data_file_info) *
fw[i]->num_of_data_files;
}

fw_list = kmalloc(size, GFP_KERNEL);
fw_list->num_of_fws = len;

itr = (char *)fw_list->fw_info;
for (i = 0; i < len; i++) {
*(ipts_bin_fw_info_t *)itr = *fw[i];
itr += sizeof(ipts_bin_fw_info_t);
*(struct ipts_bin_fw_info *)itr = *fw[i];

itr += sizeof(struct ipts_bin_fw_info);

for (j = 0; j < fw[i]->num_of_data_files; j++) {
*(ipts_bin_data_file_info_t *)itr = fw[i]->data_file[j];
itr += sizeof(ipts_bin_data_file_info_t);
*(struct ipts_bin_data_file_info *)itr =
fw[i]->data_file[j];

itr += sizeof(struct ipts_bin_data_file_info);
}
}

return fw_list;
}

int ipts_request_firmware_config(ipts_info_t *ipts, ipts_bin_fw_list_t **cfg)
int ipts_request_firmware_config(struct ipts_info *ipts,
struct ipts_bin_fw_list **cfg)
{
int ret;
const struct firmware *config_fw = NULL;

// Make sure that access to the companion is synchronized
mutex_lock(&ipts_companion_lock);

// Check if a companion was registered. If not, skip
Expand All @@ -170,20 +194,17 @@ int ipts_request_firmware_config(ipts_info_t *ipts, ipts_bin_fw_list_t **cfg)

// If fallback loading for the firmware config was disabled, abort.
// Return -ENOENT as no config file was found.
if (ipts_modparams.ignore_config_fallback) {
if (ipts_modparams.ignore_config_fallback)
return -ENOENT;
}

// No firmware config was found by the companion driver,
// try loading it from a file now
ret = ipts_request_firmware(&config_fw, IPTS_FW_CONFIG_FILE,
&ipts->cldev->dev);

if (!ret) {
*cfg = (ipts_bin_fw_list_t *)config_fw->data;
} else {
&ipts->cldev->dev);
if (!ret)
*cfg = (struct ipts_bin_fw_list *)config_fw->data;
else
release_firmware(config_fw);
}

return ret;

Expand Down
14 changes: 12 additions & 2 deletions drivers/misc/ipts/ipts-companion.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
*
* Intel Precise Touch & Stylus
* Copyright (c) 2016 Intel Corporation
*
*/

#ifndef _IPTS_COMPANION_H_
#define _IPTS_COMPANION_H_

Expand All @@ -7,9 +15,11 @@
#include "ipts.h"

bool ipts_companion_available(void);

int ipts_request_firmware(const struct firmware **fw, const char *name,
struct device *device);
int ipts_request_firmware_config(ipts_info_t *ipts,
ipts_bin_fw_list_t **firmware_config);

int ipts_request_firmware_config(struct ipts_info *ipts,
struct ipts_bin_fw_list **firmware_config);

#endif // _IPTS_COMPANION_H_

0 comments on commit 6c2bceb

Please sign in to comment.