/**
 * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
 *
 * This source file is released under GPL v2 license (no other versions).
 * See the COPYING file included in the main directory of this source
 * distribution for the license terms and conditions.
 *
 * @File	cthardware.c
 *
 * @Brief
 * This file contains the implementation of hardware access methord.
 *
 * @Author	Liu Chun
 * @Date 	Jun 26 2008
 *
 */

#include "cthardware.h"
#include "cthw20k1.h"
#include "cthw20k2.h"
#include <linux/bug.h>

int create_hw_obj(struct pci_dev *pci, enum CHIPTYP chip_type,
		  enum CTCARDS model, struct hw **rhw)
{
	int err;

	switch (chip_type) {
	case ATC20K1:
		err = create_20k1_hw_obj(rhw);
		break;
	case ATC20K2:
		err = create_20k2_hw_obj(rhw);
		break;
	default:
		err = -ENODEV;
		break;
	}
	if (err)
		return err;

	(*rhw)->pci = pci;
	(*rhw)->chip_type = chip_type;
	(*rhw)->model = model;

	return 0;
}

int destroy_hw_obj(struct hw *hw)
{
	int err;

	switch (hw->pci->device) {
	case 0x0005:	/* 20k1 device */
		err = destroy_20k1_hw_obj(hw);
		break;
	case 0x000B:	/* 20k2 device */
		err = destroy_20k2_hw_obj(hw);
		break;
	default:
		err = -ENODEV;
		break;
	}

	return err;
}

unsigned int get_field(unsigned int data, unsigned int field)
{
	int i;

	if (WARN_ON(!field))
		return 0;
	/* @field should always be greater than 0 */
	for (i = 0; !(field & (1 << i)); )
		i++;

	return (data & field) >> i;
}

void set_field(unsigned int *data, unsigned int field, unsigned int value)
{
	int i;

	if (WARN_ON(!field))
		return;
	/* @field should always be greater than 0 */
	for (i = 0; !(field & (1 << i)); )
		i++;

	*data = (*data & (~field)) | ((value << i) & field);
}

/selinux/ss/avtab.c'>log</a><a href='/cgit.cgi/linux/net-next.git/tree/security/selinux/ss/avtab.c?id=91539eb1fda2d530d3b268eef542c5414e54bf1a'>tree</a><a class='active' href='/cgit.cgi/linux/net-next.git/commit/security/selinux/ss/avtab.c?id=91539eb1fda2d530d3b268eef542c5414e54bf1a'>commit</a><a href='/cgit.cgi/linux/net-next.git/diff/security/selinux/ss/avtab.c?id=91539eb1fda2d530d3b268eef542c5414e54bf1a'>diff</a></td><td class='form'><form class='right' method='get' action='/cgit.cgi/linux/net-next.git/log/security/selinux/ss/avtab.c'>
<input type='hidden' name='id' value='91539eb1fda2d530d3b268eef542c5414e54bf1a'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/cgit.cgi/linux/net-next.git/commit/?id=91539eb1fda2d530d3b268eef542c5414e54bf1a'>root</a>/<a href='/cgit.cgi/linux/net-next.git/commit/security?id=91539eb1fda2d530d3b268eef542c5414e54bf1a'>security</a>/<a href='/cgit.cgi/linux/net-next.git/commit/security/selinux?id=91539eb1fda2d530d3b268eef542c5414e54bf1a'>selinux</a>/<a href='/cgit.cgi/linux/net-next.git/commit/security/selinux/ss?id=91539eb1fda2d530d3b268eef542c5414e54bf1a'>ss</a>/<a href='/cgit.cgi/linux/net-next.git/commit/security/selinux/ss/avtab.c?id=91539eb1fda2d530d3b268eef542c5414e54bf1a'>avtab.c</a></div><div class='content'><div class='cgit-panel'><b>diff options</b><form method='get'><input type='hidden' name='id' value='91539eb1fda2d530d3b268eef542c5414e54bf1a'/><table><tr><td colspan='2'/></tr><tr><td class='label'>context:</td><td class='ctrl'><select name='context' onchange='this.form.submit();'><option value='1'>1</option><option value='2'>2</option><option value='3' selected='selected'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='15'>15</option><option value='20'>20</option><option value='25'>25</option><option value='30'>30</option><option value='35'>35</option><option value='40'>40</option></select></td></tr><tr><td class='label'>space:</td><td class='ctrl'><select name='ignorews' onchange='this.form.submit();'><option value='0' selected='selected'>include</option><option value='1'>ignore</option></select></td></tr><tr><td class='label'>mode:</td><td class='ctrl'><select name='dt' onchange='this.form.submit();'><option value='0' selected='selected'>unified</option><option value='1'>ssdiff</option><option value='2'>stat only</option></select></td></tr><tr><td/><td class='ctrl'><noscript><input type='submit' value='reload'/></noscript></td></tr></table></form></div><table summary='commit info' class='commit-info'>
<tr><th>author</th><td>Iago Abal &lt;mail@iagoabal.eu&gt;</td><td class='right'>2017-01-11 14:00:21 +0100</td></tr>
<tr><th>committer</th><td>Vinod Koul &lt;vinod.koul@intel.com&gt;</td><td class='right'>2017-01-25 15:35:11 +0530</td></tr>
<tr><th>commit</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/commit/security/selinux/ss/avtab.c?id=91539eb1fda2d530d3b268eef542c5414e54bf1a'>91539eb1fda2d530d3b268eef542c5414e54bf1a</a> (<a href='/cgit.cgi/linux/net-next.git/patch/security/selinux/ss/avtab.c?id=91539eb1fda2d530d3b268eef542c5414e54bf1a'>patch</a>)</td></tr>
<tr><th>tree</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/tree/?id=91539eb1fda2d530d3b268eef542c5414e54bf1a'>960f5ca6342ad20837aff18aad6e8ecd7da32fd6</a> /<a href='/cgit.cgi/linux/net-next.git/tree/security/selinux/ss/avtab.c?id=91539eb1fda2d530d3b268eef542c5414e54bf1a'>security/selinux/ss/avtab.c</a></td></tr>
<tr><th>parent</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/commit/security/selinux/ss/avtab.c?id=6610d0edf6dc7ee97e46ab3a538a565c79d26199'>6610d0edf6dc7ee97e46ab3a538a565c79d26199</a> (<a href='/cgit.cgi/linux/net-next.git/diff/security/selinux/ss/avtab.c?id=91539eb1fda2d530d3b268eef542c5414e54bf1a&amp;id2=6610d0edf6dc7ee97e46ab3a538a565c79d26199'>diff</a>)</td></tr></table>
<div class='commit-subject'>dmaengine: pl330: fix double lock</div><div class='commit-msg'>The static bug finder EBA (http://www.iagoabal.eu/eba/) reported the
following double-lock bug:

    Double lock:
    1. spin_lock_irqsave(pch-&gt;lock, flags) at pl330_free_chan_resources:2236;
    2. call to function `pl330_release_channel' immediately after;
    3. call to function `dma_pl330_rqcb' in line 1753;
    4. spin_lock_irqsave(pch-&gt;lock, flags) at dma_pl330_rqcb:1505.

I have fixed it as suggested by Marek Szyprowski.

First, I have replaced `pch-&gt;lock' with `pl330-&gt;lock' in functions
`pl330_alloc_chan_resources' and `pl330_free_chan_resources'. This avoids
the double-lock by acquiring a different lock than `dma_pl330_rqcb'.

NOTE that, as a result, `pl330_free_chan_resources' executes
`list_splice_tail_init' on `pch-&gt;work_list' under lock `pl330-&gt;lock',
whereas in the rest of the code `pch-&gt;work_list' is protected by
`pch-&gt;lock'. I don't know if this may cause race conditions. Similarly
`pch-&gt;cyclic' is written by `pl330_alloc_chan_resources' under
`pl330-&gt;lock' but read by `pl330_tx_submit' under `pch-&gt;lock'.

Second, I have removed locking from `pl330_request_channel' and
`pl330_release_channel' functions. Function `pl330_request_channel' is
only called from `pl330_alloc_chan_resources', so the lock is already
held. Function `pl330_release_channel' is called from
`pl330_free_chan_resources', which already holds the lock, and from
`pl330_del'. Function `pl330_del' is called in an error path of
`pl330_probe' and at the end of `pl330_remove', but I assume that there
cannot be concurrent accesses to the protected data at those points.

Signed-off-by: Iago Abal &lt;mail@iagoabal.eu&gt;
Reviewed-by: Marek Szyprowski &lt;m.szyprowski@samsung.com&gt;
Signed-off-by: Vinod Koul &lt;vinod.koul@intel.com&gt;
</div><div class='diffstat-header'><a href='/cgit.cgi/linux/net-next.git/diff/?id=91539eb1fda2d530d3b268eef542c5414e54bf1a'>Diffstat</a> (limited to 'security/selinux/ss/avtab.c')</div><table summary='diffstat' class='diffstat'>