Commit 0cf70cc8 authored by Benjamin Berg's avatar Benjamin Berg

cocci: Remove spatch/cocci files again

They were just committed for archival purposes.
parent 9a971971
Pipeline #55723 failed with stages
in 9 minutes and 46 seconds
// Remove USB device reset, lets hope that we do not need this.
// If we do, maybe do it elsewhere?
@@
identifier r;
@@
- r = libusb_reset_device(...);
- if (r != 0) { ... }
// Functions that have uneccessary returns (i.e. error cannot happen after refactoring)
// NOTE: Make sure that these function are fine to modify in *all* drivers!
@ prior_int_func @
identifier func =~ "capture_chunk_async|alksdjflkajsfd";
expression res, res2;
@@
-int func
+void func
(...)
{
<...
- return res2;
+ res2;
...>
- return res;
+ res;
}
@@
identifier prior_int_func.func;
identifier res;
@@
-res = func
+func
(...);
(
-if (res < 0) { ... }
|
-if (res != 0) { ... }
)
// Remove useless checks of fpi_timeout_add return values
@@
expression a1, a2, a3, a4;
@@
-if (fpi_timeout_add(a1, a2, a3, a4) == NULL) { ... }
+fpi_timeout_add(a1, a2, a3, a4);
@@
identifier timeout;
expression a1, a2, a3, a4;
@@
timeout = fpi_timeout_add(a1, a2, a3, a4);
-if (timeout == NULL) { ... }
// The VFS5011 driver has some stupid "radiation detected" logic, that should be asserts
@@
expression expr;
@@
-if ((expr)) {
- ...
- fp_err("Radiation detected!");
- ...
-}
+g_assert(!expr);
// A number of drivers call both fpi_imgdev_session_error *and* fpi_ssm_mark_failed.
// While this worked fine, it is plain wrong and considerably complicates memory
// management of the errors.
// Remove this duplication
@@
expression dev;
expression ssm;
expression error;
@@
- fpi_imgdev_session_error(dev, error);
fpi_ssm_mark_failed(ssm, error);
@@
@@
- LIBUSB_ENDPOINT_IN
+ FP_USB_ENDPOINT_IN
@@
@@
- LIBUSB_ENDPOINT_OUT
+ FP_USB_ENDPOINT_OUT
@ fp_img_dev @
typedef FpImageDevice;
@@
-struct fp_img_dev
+FpImageDevice
@ FpImageDevice_cast @
typedef FpImageDevice;
expression dev;
@@
-(FpImageDevice*) dev
+FP_IMAGE_DEVICE (dev)
@ fp_dev @
typedef FpDevice;
@@
-struct fp_dev
+FpDevice
@ FpDevice_cast @
typedef FpDevice;
expression dev;
@@
-(FpDevice*) dev
+FP_DEVICE (dev)
@ FP_DEV_cast @
expression dev;
@@
- FP_DEV (dev)
+ FP_DEVICE (dev)
@ FP_IMG_DEV_cast @
expression dev;
@@
- FP_IMG_DEV (dev)
+ FP_IMAGE_DEVICE (dev)
@ fpi_ssm @
typedef fpi_ssm;
typedef FpSsm;
@@
-fpi_ssm
+FpSsm
@ fp_img @
typedef FpImage;
@@
-struct fp_img
+FpImage
@ libusb_transfer @
typedef FpUsbTransfer;
@@
-struct libusb_transfer
+FpUsbTransfer
@ libusb_device_handle @
typedef libusb_device_handle;
typedef GUsbDevice;
@@
-libusb_device_handle
+GUsbDevice
@@
expression w;
expression h;
expression status;
expression dev;
expression a1, a2, a3;
@@
(
-fpi_img_new(w * h)
+fp_image_new(w, h)
|
-fpi_ssm_new
+fp_ssm_new
|
-fpi_ssm_free
+fp_ssm_free
|
-fpi_ssm_start
+fp_ssm_start
|
-fpi_ssm_start_subsm
+fp_ssm_start_subsm
|
-fpi_ssm_next_state
+fp_ssm_next_state
|
-fpi_ssm_jump_to_state
+fp_ssm_jump_to_state
|
-fpi_ssm_mark_completed
+fp_ssm_mark_completed
|
-fpi_ssm_get_user_data
+fp_ssm_get_user_data
|
-fpi_ssm_get_cur_state
+fp_ssm_get_cur_state
|
-fpi_dev_get_usb_dev
+_fp_device_get_usb_device
|
// HACK: We just insert an error return here!
-fpi_imgdev_close_complete(dev)
+_fp_image_device_close_complete(dev, error)
|
-fpi_imgdev_open_complete(dev, 0)
+_fp_image_device_open_complete(dev, NULL)
|
-fpi_imgdev_activate_complete(dev, 0)
+_fp_image_device_activate_complete(dev, NULL)
|
-fpi_imgdev_deactivate_complete(dev)
+_fp_image_device_deactivate_complete(dev, NULL)
|
-fpi_imgdev_report_finger_status(dev, status)
+_fp_image_device_report_finger_status(dev, status)
|
-fpi_imgdev_image_captured(dev, a1)
+_fp_image_device_image_captured(dev, a1)
|
-fpi_imgdev_abort_scan
+_fp_image_device_retry_scan
|
-fpi_std_sq_dev
+_fp_std_sq_dev
|
-fpi_mean_sq_diff_norm
+_fp_mean_sq_diff_norm
|
-fpi_timeout_add(a1, a2, dev, a3)
+_fp_device_add_timeout(dev, a1, a2, a3)
)
// Some can be nested
@@
@@
(
-fpi_ssm_next_state_timeout_cb
+fp_ssm_next_state_timeout_cb
)
@@
typedef FpImageDeviceState;
@@
(
-FP_IMG_COLORS_INVERTED
+FP_IMAGE_COLORS_INVERTED
|
-FP_IMG_H_FLIPPED
+FP_IMAGE_H_FLIPPED
|
-FP_IMG_V_FLIPPED
+FP_IMAGE_V_FLIPPED
|
-FP_VERIFY_RETRY_TOO_SHORT
+FP_DEVICE_RETRY_TOO_SHORT
|
-FP_VERIFY_RETRY_CENTER_FINGER
+FP_DEVICE_RETRY_CENTER_FINGER
|
-FP_VERIFY_RETRY
+FP_DEVICE_RETRY
)
@@
@@
(
-enum fp_imgdev_state
+FpImageDeviceState
)
@ dev_func @
identifier dev;
identifier func;
@@
func(..., FpDevice *dev, ...)
{
...
}
@ imgdev_func @
identifier dev;
identifier func;
@@
func(..., FpImageDevice *dev, ...)
{
...
}
@ self_func extends driver @
identifier self;
identifier func;
@@
func(..., driver_cls *self, ...)
{
...
}
@ transfer_func_imgdev @
typedef FpUsbTransfer;
identifier imgdev_func.func;
identifier imgdev_func.dev;
identifier transfer;
@@
func (...)
{
<...
(
-transfer = fpi_usb_alloc();
+transfer = fp_usb_transfer_new(FP_DEVICE (dev));
|
-FpUsbTransfer *transfer = fpi_usb_alloc();
+FpUsbTransfer *transfer = fp_usb_transfer_new(FP_DEVICE (dev));
)
...>
}
@ transfer_func_dev @
typedef FpUsbTransfer;
identifier dev_func.func;
identifier dev_func.dev;
identifier transfer;
@@
func (...)
{
<...
(
-transfer = fpi_usb_alloc();
+transfer = fp_usb_transfer_new(dev);
|
-FpUsbTransfer *transfer = fpi_usb_alloc();
+FpUsbTransfer *transfer = fp_usb_transfer_new(dev);
)
...>
}
@ transfer_func_self @
typedef FpUsbTransfer;
identifier self_func.func;
identifier self_func.self;
expression transfer;
@@
func (...)
{
<...
-transfer = fpi_usb_alloc();
+transfer = fp_usb_transfer_new(FP_DEVICE (self));
...>
}
// None of the release interface calls had error handling ...
@ extends driver @
expression usb_dev;
expression interface;
@@
dev_close(...)
{
+ GError *error = NULL;
...
-libusb_release_interface(usb_dev, interface);
+g_usb_device_release_interface(usb_dev, interface, 0, &error);
...
}
@ extends driver @
expression usb_dev;
expression interface;
identifier imgdev;
identifier r;
@@
dev_open (..., FpImageDevice *imgdev, ...)
{
+ GError *error = NULL;
...
-r = libusb_claim_interface(usb_dev, interface);
+if (!g_usb_device_claim_interface(usb_dev, interface, 0, &error)) {
+ _fp_image_device_open_complete (imgdev, error);
+ return;
+ }
(
-if (r != 0) { ... }
|
-if (r < 0) { ... }
)
...
}
@ usb_transfer_cb @
typedef FpUsbTransfer;
typedef FpSsm;
identifier func;
identifier transfer;
identifier dev;
identifier ssm;
@@
(
-void func(FpUsbTransfer *transfer)
+void func(FpUsbTransfer *transfer,
+ FpDevice *device,
+ gpointer user_data,
+ GError *error)
{
...
}
|
// this is weird, one function in uru4000 didn't get the types
// converted by earlier rules. But, this does not seem to work either.
-void func(\(FpUsbTransfer*\|struct libusb_transfer*\) transfer,
- \(FpDevice*\|struct fp_dev*\) dev,
- \(FpSsm*\|fpi_ssm*\) ssm,
- void* user_data)
+void func(FpUsbTransfer *transfer,
+ FpDevice *dev,
+ gpointer user_data,
+ GError *error)
{
+ FpSsm *ssm = transfer->ssm;
...
}
)
@ errors_generic_1 @
identifier usb_transfer_cb.func;
identifier usb_transfer_cb.transfer;
@@
func(...)
{
<...
(
- (transfer->status != LIBUSB_TRANSFER_COMPLETED)
+ error
|
- (transfer->status == LIBUSB_TRANSFER_COMPLETED)
+ !error
|
- (transfer->status == LIBUSB_TRANSFER_TIMED_OUT)
+ g_error_matches (error, G_USB_DEVICE_ERROR, G_USB_DEVICE_ERROR_TIMED_OUT)
)
...>
}
@ errors_1 @
identifier usb_transfer_cb.func;
identifier usb_transfer_cb.transfer;
expression ssm;
statement S;
@@
func(...)
{
<...
if (error) {
(
...
- fpi_ssm_mark_failed (ssm, ...)
+ fp_ssm_mark_failed (ssm, error)
...
|
...
- fpi_imgdev_session_error (...)
+ _fp_image_device_session_error (FP_IMAGE_DEVICE (device), error)
...
)
}
...>
}
@ errors_1_alt @
identifier usb_transfer_cb.func;
identifier usb_transfer_cb.transfer;
expression ssm;
statement S;
@@
func(...)
{
<...
if (!error) { ... }
else {
(
...
- fpi_ssm_mark_failed (ssm, ...)
+ fp_ssm_mark_failed (ssm, error)
...
|
...
- fpi_imgdev_session_error (...)
+ _fp_image_device_session_error (FP_IMAGE_DEVICE (device), error)
...
)
}
...>
}
@ errors_2 @
identifier usb_transfer_cb.func;
identifier usb_transfer_cb.transfer;
expression ssm;
@@
func(...)
{
<...
if (transfer->length != transfer->actual_length) {
+ _Pragma("GCC warning \"Driver should probably set short_is_error instead!\"");
...
(
- fpi_ssm_mark_failed (ssm, ...);
+ fp_ssm_mark_failed (ssm, g_error_new (G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_IO,
+ "Short USB transfer!"));
|
- fpi_imgdev_session_error (...);
+ _fp_image_device_session_error (FP_IMAGE_DEVICE (device),
+ g_error_new (G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_IO,
+ "Short USB transfer!"));
)
...
}
...>
}
@ not_useful_error_prints @
identifier usb_transfer_cb.func;
@@
func(...)
{
<...
- fp_err (...);
...
(
fp_ssm_mark_failed (...);
|
_fp_image_device_session_error (...);
)
...>
}
@ error_or_wrong_length @
identifier usb_transfer_cb.func;
identifier usb_transfer_cb.transfer;
expression ssm;
@@
func(...)
{
<...
- if (error || (transfer->length != transfer->actual_length))
+ if (error)
{
+ _Pragma("GCC warning \"Driver needs to set short_is_error for this branch to be taken!\"");
<...
(
- fpi_ssm_mark_failed (ssm, ...);
+ fp_ssm_mark_failed (ssm, error);
|
- fpi_imgdev_session_error (...);
+ _fp_image_device_session_error (FP_IMAGE_DEVICE (device), error);
)
...>
}
...>
}
@ error_or_wrong_length_2 @
identifier usb_transfer_cb.func;
identifier usb_transfer_cb.transfer;
expression ssm;
@@
func(...)
{
<...
- if (!error && (transfer->length == transfer->actual_length))
+ if (!error)
{ ... }
else {
+ _Pragma("GCC warning \"Driver needs to set short_is_error for this branch to be taken!\"");
<...
(
- fpi_ssm_mark_failed (ssm, ...);
+ fp_ssm_mark_failed (ssm, error);
|
- fpi_imgdev_session_error (...);
+ _fp_image_device_session_error (FP_IMAGE_DEVICE (device), error);
)
...>
}
...>
}
@@
identifier usb_transfer_cb.func;
identifier usb_transfer_cb.transfer;
identifier out;
@@
func(...)
{
<...
- goto out;
+ return;
...>
-out:
(
- g_free(transfer->buffer);
|
)
- libusb_free_transfer (transfer);
}
@@
identifier usb_transfer_cb.func;
identifier usb_transfer_cb.transfer;
@@
func(...)
{
<...
(
- g_free(transfer->buffer);
|
)
- libusb_free_transfer (transfer);
...
return;
...>
}
@@
identifier usb_transfer_cb.func;
identifier usb_transfer_cb.transfer;
@@
func(...)
{
<...
- transfer->user_data
+ user_data
...>
}
@@
typedef gint;
identifier usb_transfer_cb.func;
identifier usb_transfer_cb.transfer;
@@
func(...)
{
<...
(
fp_dbg
|
fp_warn
|
fp_err
)
(...,
- transfer->length
+ (gint) transfer->length
, ...);
...>
}
@@
typedef gint;
identifier usb_transfer_cb.func;
identifier usb_transfer_cb.transfer;
@@
func(...)
{
<...
(
fp_dbg
|
fp_warn
|
fp_err
)
(...,
- transfer->actual_length
+ (gint) transfer->actual_length
, ...);
...>
}
@@
identifier usb_transfer_cb.func;
identifier usb_transfer_cb.transfer;
identifier ssm_var;
gpointer user_data;
@@
func(...)
{
...
(
- FpSsm *ssm_var = (FpSsm*) user_data;
|
- FpSsm *ssm_var = user_data;
)
<...
- ssm_var
+ transfer->ssm
...>
}
// A lot of drivers abuse the SSM user_data for the driver
// Convert FpImageDevice usage to simple cast
@@
identifier usb_transfer_cb.func;
identifier dev;
@@
func(...)
{
-FpImageDevice *dev = ...;
+FpImageDevice *dev = FP_IMAGE_DEVICE (device);
...
}
// A lot of drivers abuse the SSM user_data for the driver
// Remove FpDevice getter and use argument
@@
identifier usb_transfer_cb.func;
identifier arg;
identifier dev;
@@
func(..., FpDevice *arg, ...)
{
-FpDevice *dev = ...;
<...
-dev
+arg
...>
}
///////////////////////////////////////////////////////////////////////////
// bulk transfers
@@
typedef FpUsbTransfer;
expression transfer;
expression usb_dev;
expression endpoint;
expression data;
expression size;
expression cb;
expression user_data;
expression timeout;
identifier ret;
@@
- libusb_fill_bulk_transfer(transfer, usb_dev, endpoint, data, size, cb, user_data, timeout);
+ fp_usb_transfer_fill_bulk_full(transfer, endpoint, data, size, NULL);
+ fp_usb_transfer_submit(transfer, timeout, NULL, cb, user_data);
+ fp_usb_transfer_unref(transfer);
(
- ret = libusb_submit_transfer(transfer);
...
(
- if (ret < 0) { ... }
|
- if (ret != 0) { ... }
|
)
|
- if (libusb_submit_transfer(transfer)) { ... }
|
- if (libusb_submit_transfer(transfer) < 0) { ... }
|
- libusb_submit_transfer(transfer);
)
///////////////////////////////////////////////////////////////////////////
// bulk transfers
@@
typedef FpUsbTransfer;
expression transfer;
expression dev;
expression transfer_ssm;
expression endpoint;
expression data;
expression size;
expression cb;
expression user_data;
expression timeout;
expression storage;
identifier ret;
@@
- transfer = fpi_usb_fill_bulk_transfer(dev, transfer_ssm, endpoint, data, size, cb, user_data, timeout);
+ transfer = fp_usb_transfer_new (dev);
+ transfer->ssm = transfer_ssm;