Skip to content

Commit d9bc633

Browse files
committed
ipts: Address comments by qzed and grayhatter
* Removed some of the gotos in the simpler companion function * Made the companion driver the first parameter in the firmware handler * Changed ipts-surface to warn when adding the companion driver failed * Made ipts_alloc_fw_list static Signed-off-by: Dorian Stoll <dorian.stoll@tmsp.io>
1 parent e1cfd84 commit d9bc633

File tree

3 files changed

+20
-27
lines changed

3 files changed

+20
-27
lines changed

drivers/misc/ipts/companion/ipts-surface.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
MODULE_FIRMWARE("intel/ipts/" X "/vendor_desc.bin"); \
1414
MODULE_FIRMWARE("intel/ipts/" X "/vendor_kernel.bin"); \
1515

16-
int ipts_surface_request_firmware(const struct firmware **fw, const char *name,
17-
struct device *device, ipts_companion_t *companion)
16+
int ipts_surface_request_firmware(ipts_companion_t *companion,
17+
const struct firmware **fw, const char *name,
18+
struct device *device)
1819
{
1920
char fw_path[MAX_IOCL_FILE_PATH_LEN];
2021

@@ -77,7 +78,7 @@ static int ipts_surface_probe(struct platform_device *pdev)
7778
ipts_surface_companion.data = (void *)acpi_device_hid(adev);
7879
ret = ipts_add_companion(&ipts_surface_companion);
7980
if (ret) {
80-
dev_info(&pdev->dev, "Adding IPTS companion failed, "
81+
dev_warn(&pdev->dev, "Adding IPTS companion failed, "
8182
"error: %d\n", ret);
8283
return ret;
8384
}
@@ -89,7 +90,7 @@ static int ipts_surface_remove(struct platform_device *pdev)
8990
{
9091
int ret = ipts_remove_companion(&ipts_surface_companion);
9192
if (ret) {
92-
dev_info(&pdev->dev, "Removing IPTS companion failed, "
93+
dev_warn(&pdev->dev, "Removing IPTS companion failed, "
9394
"error: %d\n", ret);
9495
}
9596

drivers/misc/ipts/ipts-companion.c

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,34 @@ bool ipts_companion_available(void)
3535

3636
int ipts_add_companion(ipts_companion_t *companion)
3737
{
38-
int ret = 0;
38+
int ret;
3939
mutex_lock(&ipts_companion_lock);
4040

41-
if (ipts_companion != NULL) {
41+
if (ipts_companion == NULL) {
42+
ret = 0;
43+
ipts_companion = companion;
44+
} else {
4245
ret = -EBUSY;
43-
goto add_companion_return;
4446
}
4547

46-
ipts_companion = companion;
47-
48-
add_companion_return:
49-
5048
mutex_unlock(&ipts_companion_lock);
5149
return ret;
5250
}
5351
EXPORT_SYMBOL_GPL(ipts_add_companion);
5452

5553
int ipts_remove_companion(ipts_companion_t *companion)
5654
{
57-
int ret = 0;
55+
int ret;
5856
mutex_lock(&ipts_companion_lock);
5957

60-
if (ipts_companion == NULL || companion == NULL) {
61-
ret = 0;
62-
goto remove_companion_return;
63-
}
64-
65-
if (ipts_companion->name != companion->name) {
58+
if (ipts_companion != NULL && companion != NULL &&
59+
ipts_companion->name != companion->name) {
6660
ret = -EPERM;
67-
goto remove_companion_return;
61+
} else {
62+
ret = 0;
63+
ipts_companion = NULL;
6864
}
6965

70-
ipts_companion = NULL;
71-
72-
remove_companion_return:
73-
7466
mutex_unlock(&ipts_companion_lock);
7567
return ret;
7668
}
@@ -95,7 +87,7 @@ int ipts_request_firmware(const struct firmware **fw, const char *name,
9587
goto request_firmware_fallback;
9688
}
9789

98-
ret = ipts_companion->firmware_request(fw, name, device, ipts_companion);
90+
ret = ipts_companion->firmware_request(ipts_companion, fw, name, device);
9991
if (!ret) {
10092
goto request_firmware_return;
10193
}
@@ -119,7 +111,7 @@ int ipts_request_firmware(const struct firmware **fw, const char *name,
119111
return ret;
120112
}
121113

122-
ipts_bin_fw_list_t *ipts_alloc_fw_list(ipts_bin_fw_info_t **fw)
114+
static ipts_bin_fw_list_t *ipts_alloc_fw_list(ipts_bin_fw_info_t **fw)
123115
{
124116
int size, len, i, j;
125117
ipts_bin_fw_list_t *fw_list;

include/linux/ipts-companion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
typedef struct ipts_companion ipts_companion_t;
88

9-
typedef int (*ipts_fw_handler_t)(const struct firmware **, const char *,
10-
struct device *, ipts_companion_t *companion);
9+
typedef int (*ipts_fw_handler_t)(ipts_companion_t *, const struct firmware **,
10+
const char *, struct device *);
1111

1212
struct ipts_companion {
1313
ipts_fw_handler_t firmware_request;

0 commit comments

Comments
 (0)