staging/zcache: Fix/improve zcache writeback code, tie to a config option

It was observed by Andrea Arcangeli in 2011 that zcache can get "full"
and there must be some way for compressed swap pages to be (uncompressed
and then) sent through to the backing swap disk.  A prototype of this
functionality, called "unuse", was added in 2012 as part of a major update
to zcache (aka "zcache2"), but was left unfinished due to the unfortunate
temporary fork of zcache.

This earlier version of the code had an unresolved memory leak
and was anyway dependent on not-yet-upstream frontswap and mm changes.
The code was meanwhile adapted by Seth Jennings for similar
functionality in zswap (which he calls "flush").  Seth also made some
clever simplifications which are herein ported back to zcache.  As a
result of those simplifications, the frontswap changes are no longer
necessary, but a slightly different (and simpler) set of mm changes are
still required [1].  The memory leak is also fixed.

Due to feedback from akpm in a zswap thread, this functionality in zcache
has now been renamed from "unuse" to "writeback".

Although this zcache writeback code now works, there are open questions
as how best to handle the policy that drives it.  As a result, this
patch also ties writeback to a new config option.  And, since the
code still depends on not-yet-upstreamed mm patches, to avoid build
problems, the config option added by this patch temporarily depends
on "BROKEN"; this config dependency can be removed in trees that
contain the necessary mm patches.

[1] https://lkml.org/lkml/2013/1/29/540/ https://lkml.org/lkml/2013/1/29/539/

Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging: dgrp: remove redundant NULL check before unregister_dgrp_device().

unregister_dgrp_device on a NULL pointer is a no-op, so the NULL checks in
dgrp_remove_nd() can be removed.

Signed-off-by: Cyril Roelandt <tipecaml@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging: tidspbridge: remove redundant NULL check before delete_msg_mgr().

delete_msg_mgr on a NULL pointer is a no-op, so the NULL check in
bridge_msg_delete can be removed.

Signed-off-by: Cyril Roelandt <tipecaml@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging/comedi: Fix undefined array subscript

In vmk80xx_do_insn_bits the local variable reg, which is used as an
index to the tx_buf array, can be used uninitialized if
- data[0] == 0
and
- devpriv->model != VMK8061_MODEL
-> we get into the else branch without having reg initialized.

Since the driver usually differentiates between VMK8061_MODEL and
VMK8055_MODEL it's safe to assume that VMK8055_DO_REG was meant as an
initial value.

And to avoid duplication we can move the assignments to the top.

Acked-by: Ian Abbott <abbotti@mev.co.uk>
Acked-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging: zcache: add TODO file

Add zcache TODO file

Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging/wlan-ng: Fix 'Branch condition evaluates to a garbage value' in p80211netdev.c

clang/scan-build complains that:
p80211netdev.c:451:6: warning: Branch condition evaluates to a garbage
value
        if ((p80211_wep.data) && (p80211_wep.data != skb->data))
	            ^~~~~~~~~~~~~~~~~

This can happen in p80211knetdev_hard_start_xmit if
- if (wlandev->state != WLAN_DEVICE_OPEN) evaluates to true.
the execution flow then continues at the 'failed' label where
p80211_wep.data is used without being initialized first.

-> Initialize the data field to NULL to fix this issue.

Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging/rtl8192u/ieee80211: Fix buffer overflow in ieee80211_softmac_wx.c

Clang/scan-build complains about a possible buffer overflow in
ieee80211_wx_get_name:

.../staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c:499:3:
warning: String copy function overflows destination buffer
	strcat(wrqu->name," link..");

.../staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c:497:3:
warning: String copy function overflows destination buffer
	strcat(wrqu->name," linked");

The buffer wrqu->name is only IFNAMSIZ bytes big (currently 16),
so if we have a "802.11b/g/n linked" device we overrun the buffer by 3
bytes.

-> Use strlcopy / strlcat to populate the name.
This is done in a similar fashion in
staging/rtl8187se/ieee80211/ieee80211_softmac_wx.c

While at it cleaned some whitespace issues.

Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
zcache: Fix compile warnings due to usage of debugfs_create_size_t

When we compile we get tons of:
include/linux/debugfs.h:80:16: note: expected ‘size_t *’ but argument is
of type ‘long int *’
drivers/staging/zcache/zcache-main.c:279:2: warning: passing argument 4
of ‘debugfs_create_size_t’ from incompatible pointer type [enabled by d
efault]

which is b/c we end up using 'unsigned' or 'unsigned long' instead
of 'ssize_t'. So lets fix this up and use the proper type.

[v2: Rebased directly on staging]
Acked-by: Dan Magenheimer <dan.magenheimer@oracle.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
ramster: Fix compile warnings due to usage of debugfs_create_size_t

We get tons of "note: expected ‘size_t *’ but argument is of type ‘long
int *’" warnings. This fixes it.

Acked-by: Dan Magenheimer <dan.magenheimer@oracle.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
zbud: Fix compile warnings due to usage of debugfs_create_size_t

.
drivers/staging/zcache/zbud.c:336: warning: passing argument 4 of ‘debugfs_create_size_t’ from incompatible pointer type
include/linux/debugfs.h:80: note: expected ‘size_t *’ but argument is of type ‘long unsigned int *’
..

which is b/c we end up using 'unsigned' or 'unsigned long' instead
of 'ssize_t'. So lets fix this up and use the proper type.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
zcache/zbud: Fix __init mismatch

We get:
WARNING: drivers/staging/zcache/zcache.o(.text+0x13a1): Section mismatch
in reference from the function zcache_init() to the function
.init.text:zbud_init()
The function zcache_init() references
the function __init zbud_init().
This is often because zcache_init lacks a __init
annotation or the annotation of zbud_init is wrong.

And this fixes it.

Acked-by: Dan Magenheimer <dan.magenheimer@oracle.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging: comedi: vmk80xx: zero buffers on allocation

Zero out `devpriv->usb_tx_buf` and `devpriv->usb_rx_buf` on allocation.
When sending data to the USB device, this ensures any unused part of the
buffer will not contain random crap.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging: comedi: vmk80xx: simplify vmk80xx_reset_device()

vmk80xx_reset_device() is called during initialization of a Velleman
K8055 (aka VM110) to send a reset command to the hardware.  The current
function is a bit long-winded and doesn't set the TRANS_OUT_BUSY flag to
prevent re-use of the transmit buffer while the URB is in progress.

Rewrite the function to use vmk80xx_write_packet() to send the command.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging: comedi: vmk80xx: initialize K8055 outputs to known state

vmk8055_reset_device() is called during initialization of a Velleman
K8055 (aka VM110) to send a reset command to the hardware.  I don't know
what this does, but I know that it doesn't reset the digital outputs as
I've tried it.  Since the hardware does not have any way to query the
current output values and there is only the one command to update all
the analog and digital outputs simultaneously (VMK8055_CMD_WRT_AD), send
this command during initialization to set all the analog and digital
outputs to a known state.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging/comedi: Use && instead of & for logical comparision

sparse complains that:
drivers/staging/comedi/drivers/adl_pci9118.c:813 pci9118_calc_divisors()
warn: maybe use && instead of &

usessh is used as a boolean flag (0 and 1) and is compared to a boolean
value so we should use && here.

Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging/comedi: Remove if(); statement without effect

Smatch warns about:
staging/comedi/drivers/cb_pcidas64.c:3304 prep_ao_dma() warn: if();

So the check currently does nothing and can be removed, as indicated by
Ian.

Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging/panel: Mark local functions/structs static and add const if applicable (fix sparse warnings)

sparse complains about the following functions:
panel.c:188:1: warning: symbol 'logical_inputs' was not declared. Should it be static?
panel.c:569:6: warning: symbol 'old_keypad_profile' was not declared. Should it be static?
panel.c:580:6: warning: symbol 'new_keypad_profile' was not declared. Should it be static?
panel.c:593:6: warning: symbol 'nexcom_keypad_profile' was not declared. Should it be static?
panel.c:672:6: warning: symbol 'pin_to_bits' was not declared. Should it be static?
panel.c:1375:6: warning: symbol 'panel_lcd_print' was not declared. Should it be static?
panel.c:1382:6: warning: symbol 'lcd_init' was not declared. Should it be static?
panel.c:2181:5: warning: symbol 'panel_init' was not declared. Should it be static?

Add the static keyword to silence these warnings and make sparse happy.

If structs or function parameters are used readonly they are also marked
as const.

CC: David Howells <dhowells@redhat.com>
Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging/ozwpan: Fix NULL vs zero in ozpd.c (sparse warning)

This patch fixes the warning "Using plain integer as NULL pointer",
generated by sparse, by replacing the offending 0s with NULL.

If the initialization with NULL was unnecessary (due to unconditional
assignment before first use) it was removed.

Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging/ozwpan: Fix NULL vs zero in ozusbsvc1.c (sparse warning)

This patch fixes the warning "Using plain integer as NULL pointer",
generated by sparse, by replacing the offending 0s with NULL.

If the initialization with NULL was unnecessary (due to unconditional
assignment before first use) it was removed.

Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging/ozwpan: Fix NULL vs zero in ozeltbuf.c (sparse warning)

This patch fixes the warning "Using plain integer as NULL pointer",
generated by sparse, by replacing the offending 0s with NULL.

If the initialization with NULL was unnecessary (due to unconditional
assignment before first use) it was removed.

Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>