From 1a55f38d630285b53b83f6809c34c599d43f02c0 Mon Sep 17 00:00:00 2001 From: Wolfram Sang Date: Thu, 11 Aug 2016 23:23:38 +0200 Subject: staging: comedi: drivers: usbduxfast: don't print error when allocating urb fails kmalloc will print enough information in case of failure. Signed-off-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/usbduxfast.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/comedi/drivers/usbduxfast.c b/drivers/staging/comedi/drivers/usbduxfast.c index 10f94ec34536..608403c7586b 100644 --- a/drivers/staging/comedi/drivers/usbduxfast.c +++ b/drivers/staging/comedi/drivers/usbduxfast.c @@ -946,10 +946,8 @@ static int usbduxfast_auto_attach(struct comedi_device *dev, } devpriv->urb = usb_alloc_urb(0, GFP_KERNEL); - if (!devpriv->urb) { - dev_err(dev->class_dev, "Could not alloc. urb\n"); + if (!devpriv->urb) return -ENOMEM; - } devpriv->inbuf = kmalloc(SIZEINBUF, GFP_KERNEL); if (!devpriv->inbuf) -- cgit v1.2.3 From f11055b9aeb8f7cf7c4780fd071467424a7e661d Mon Sep 17 00:00:00 2001 From: Wolfram Sang Date: Thu, 11 Aug 2016 23:23:39 +0200 Subject: staging: media: lirc: lirc_imon: don't print error when allocating urb fails kmalloc will print enough information in case of failure. Signed-off-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/media/lirc/lirc_imon.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/media/lirc/lirc_imon.c b/drivers/staging/media/lirc/lirc_imon.c index ff1926ca1f96..a183e68ec320 100644 --- a/drivers/staging/media/lirc/lirc_imon.c +++ b/drivers/staging/media/lirc/lirc_imon.c @@ -797,16 +797,11 @@ static int imon_probe(struct usb_interface *interface, goto free_rbuf; } rx_urb = usb_alloc_urb(0, GFP_KERNEL); - if (!rx_urb) { - dev_err(dev, "%s: usb_alloc_urb failed for IR urb\n", __func__); + if (!rx_urb) goto free_lirc_buf; - } tx_urb = usb_alloc_urb(0, GFP_KERNEL); - if (!tx_urb) { - dev_err(dev, "%s: usb_alloc_urb failed for display urb\n", - __func__); + if (!tx_urb) goto free_rx_urb; - } mutex_init(&context->ctx_lock); context->vfd_proto_6p = vfd_proto_6p; -- cgit v1.2.3 From 86b368dbfd8378f1a58008b92d9652c8a80e56ad Mon Sep 17 00:00:00 2001 From: Wolfram Sang Date: Thu, 11 Aug 2016 23:23:40 +0200 Subject: staging: media: lirc: lirc_sasem: don't print error when allocating urb fails kmalloc will print enough information in case of failure. Signed-off-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/media/lirc/lirc_sasem.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/media/lirc/lirc_sasem.c b/drivers/staging/media/lirc/lirc_sasem.c index 2218d0042030..b080fde6d740 100644 --- a/drivers/staging/media/lirc/lirc_sasem.c +++ b/drivers/staging/media/lirc/lirc_sasem.c @@ -758,17 +758,12 @@ static int sasem_probe(struct usb_interface *interface, } rx_urb = usb_alloc_urb(0, GFP_KERNEL); if (!rx_urb) { - dev_err(&interface->dev, - "%s: usb_alloc_urb failed for IR urb\n", __func__); alloc_status = 5; goto alloc_status_switch; } if (vfd_ep_found) { tx_urb = usb_alloc_urb(0, GFP_KERNEL); if (!tx_urb) { - dev_err(&interface->dev, - "%s: usb_alloc_urb failed for VFD urb", - __func__); alloc_status = 6; goto alloc_status_switch; } -- cgit v1.2.3 From ca47d8f3ff7b3ee5ca04e03bc22052c3d1dbd5e2 Mon Sep 17 00:00:00 2001 From: Wolfram Sang Date: Thu, 11 Aug 2016 23:23:41 +0200 Subject: staging: most: hdm-usb: hdm_usb: don't print error when allocating urb fails kmalloc will print enough information in case of failure. Signed-off-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/hdm-usb/hdm_usb.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/most/hdm-usb/hdm_usb.c b/drivers/staging/most/hdm-usb/hdm_usb.c index aeae071f2823..9ec29788c047 100644 --- a/drivers/staging/most/hdm-usb/hdm_usb.c +++ b/drivers/staging/most/hdm-usb/hdm_usb.c @@ -650,10 +650,8 @@ static int hdm_enqueue(struct most_interface *iface, int channel, return -ENODEV; urb = usb_alloc_urb(NO_ISOCHRONOUS_URB, GFP_ATOMIC); - if (!urb) { - dev_err(dev, "Failed to allocate URB\n"); + if (!urb) return -ENOMEM; - } anchor = kzalloc(sizeof(*anchor), GFP_ATOMIC); if (!anchor) { -- cgit v1.2.3 From e89549b91e484fe592af3ec2b4780bed716d1c2e Mon Sep 17 00:00:00 2001 From: Wolfram Sang Date: Thu, 11 Aug 2016 23:23:42 +0200 Subject: staging: rtl8192u: r8192U_core: don't print error when allocating urb fails kmalloc will print enough information in case of failure. Signed-off-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/rtl8192u/r8192U_core.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c index dd0970facdf5..7af1af8c6616 100644 --- a/drivers/staging/rtl8192u/r8192U_core.c +++ b/drivers/staging/rtl8192u/r8192U_core.c @@ -1702,11 +1702,8 @@ short rtl8192_tx(struct net_device *dev, struct sk_buff *skb) } if (bSend0Byte) { tx_urb_zero = usb_alloc_urb(0, GFP_ATOMIC); - if (!tx_urb_zero) { - RT_TRACE(COMP_ERR, - "can't alloc urb for zero byte\n"); + if (!tx_urb_zero) return -ENOMEM; - } usb_fill_bulk_urb(tx_urb_zero, udev, usb_sndbulkpipe(udev, idx_pipe), &zero, 0, tx_zero_isr, dev); -- cgit v1.2.3 From 68d81dea4fc105666516146f6c5e91aa0fe1be02 Mon Sep 17 00:00:00 2001 From: Wolfram Sang Date: Thu, 11 Aug 2016 23:23:43 +0200 Subject: staging: vt6656: main_usb: don't print error when allocating urb fails kmalloc will print enough information in case of failure. Signed-off-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/vt6656/main_usb.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c index ac4fecb30d0e..0594828bdabf 100644 --- a/drivers/staging/vt6656/main_usb.c +++ b/drivers/staging/vt6656/main_usb.c @@ -440,10 +440,8 @@ static bool vnt_alloc_bufs(struct vnt_private *priv) /* allocate URBs */ tx_context->urb = usb_alloc_urb(0, GFP_KERNEL); - if (!tx_context->urb) { - dev_err(&priv->usb->dev, "alloc tx urb failed\n"); + if (!tx_context->urb) goto free_tx; - } tx_context->in_use = false; } @@ -462,10 +460,8 @@ static bool vnt_alloc_bufs(struct vnt_private *priv) /* allocate URBs */ rcb->urb = usb_alloc_urb(0, GFP_KERNEL); - if (!rcb->urb) { - dev_err(&priv->usb->dev, "Failed to alloc rx urb\n"); + if (!rcb->urb) goto free_rx_tx; - } rcb->skb = dev_alloc_skb(priv->rx_buf_sz); if (!rcb->skb) @@ -479,10 +475,8 @@ static bool vnt_alloc_bufs(struct vnt_private *priv) } priv->interrupt_urb = usb_alloc_urb(0, GFP_KERNEL); - if (!priv->interrupt_urb) { - dev_err(&priv->usb->dev, "Failed to alloc int urb\n"); + if (!priv->interrupt_urb) goto free_rx_tx; - } priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL); if (!priv->int_buf.data_buf) { -- cgit v1.2.3 From 58043f2527fe012e48ce30a5386c9763c88e5dd3 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Sun, 17 Jul 2016 13:14:57 +0200 Subject: staging: ks7010: Delete unnecessary checks before the function call "kfree" The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the calls is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Acked-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/ks7010/ks7010_sdio.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/ks7010/ks7010_sdio.c b/drivers/staging/ks7010/ks7010_sdio.c index b7337fd813d5..7da6c841e2cc 100644 --- a/drivers/staging/ks7010/ks7010_sdio.c +++ b/drivers/staging/ks7010/ks7010_sdio.c @@ -732,8 +732,7 @@ static int ks7010_sdio_update_index(struct ks_wlan_private *priv, u32 index) goto error_out; } error_out: - if (data_buf) - kfree(data_buf); + kfree(data_buf); return rc; } @@ -763,8 +762,7 @@ static int ks7010_sdio_data_compare(struct ks_wlan_private *priv, u32 address, goto error_out; } error_out: - if (read_buf) - kfree(read_buf); + kfree(read_buf); return rc; } @@ -879,8 +877,7 @@ static int ks7010_upload_firmware(struct ks_wlan_private *priv, release_firmware(fw_entry); error_out0: sdio_release_host(card->func); - if (rom_buf) - kfree(rom_buf); + kfree(rom_buf); return rc; } @@ -1199,9 +1196,7 @@ static void ks7010_sdio_remove(struct sdio_func *func) unregister_netdev(netdev); trx_device_exit(priv); - if (priv->ks_wlan_hw.read_buf) { - kfree(priv->ks_wlan_hw.read_buf); - } + kfree(priv->ks_wlan_hw.read_buf); free_netdev(priv->net_dev); card->priv = NULL; } -- cgit v1.2.3 From eeed92c0c0829e63c04a9f2c0c1926a4a48f6c0a Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Sun, 17 Jul 2016 13:38:46 +0200 Subject: staging: ks7010: Delete unnecessary assignments for buffer variables A few variables were assigned a null pointer despite of the detail that they were immediately reassigned by the following statement. Thus remove such unnecessary assignments. Signed-off-by: Markus Elfring Reviewed-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/ks7010/ks7010_sdio.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/ks7010/ks7010_sdio.c b/drivers/staging/ks7010/ks7010_sdio.c index 7da6c841e2cc..3622fba8fd36 100644 --- a/drivers/staging/ks7010/ks7010_sdio.c +++ b/drivers/staging/ks7010/ks7010_sdio.c @@ -711,7 +711,6 @@ static int ks7010_sdio_update_index(struct ks_wlan_private *priv, u32 index) int rc = 0; int retval; unsigned char *data_buf; - data_buf = NULL; data_buf = kmalloc(sizeof(u32), GFP_KERNEL); if (!data_buf) { @@ -743,7 +742,7 @@ static int ks7010_sdio_data_compare(struct ks_wlan_private *priv, u32 address, int rc = 0; int retval; unsigned char *read_buf; - read_buf = NULL; + read_buf = kmalloc(ROM_BUFF_SIZE, GFP_KERNEL); if (!read_buf) { rc = 1; @@ -776,8 +775,6 @@ static int ks7010_upload_firmware(struct ks_wlan_private *priv, int length; const struct firmware *fw_entry = NULL; - rom_buf = NULL; - /* buffer allocate */ rom_buf = kmalloc(ROM_BUFF_SIZE, GFP_KERNEL); if (!rom_buf) { -- cgit v1.2.3 From 695872eae5cb8292ad5a748451453468f0576001 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Sun, 17 Jul 2016 19:26:15 +0200 Subject: staging: ks7010: Delete a variable in write_to_device() The local variable "rc" was assigned a zero at one place. But it was not read within this function. Thus delete it. Signed-off-by: Markus Elfring Reviewed-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/ks7010/ks7010_sdio.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/ks7010/ks7010_sdio.c b/drivers/staging/ks7010/ks7010_sdio.c index 3622fba8fd36..a0facfc54e4b 100644 --- a/drivers/staging/ks7010/ks7010_sdio.c +++ b/drivers/staging/ks7010/ks7010_sdio.c @@ -297,11 +297,10 @@ static int enqueue_txdev(struct ks_wlan_private *priv, unsigned char *p, static int write_to_device(struct ks_wlan_private *priv, unsigned char *buffer, unsigned long size) { - int rc, retval; + int retval; unsigned char rw_data; struct hostif_hdr *hdr; hdr = (struct hostif_hdr *)buffer; - rc = 0; DPRINTK(4, "size=%d\n", hdr->size); if (hdr->event < HIF_DATA_REQ || HIF_REQ_MAX < hdr->event) { -- cgit v1.2.3 From 6bef3f01398dc12532873f8b2376dba1339908bb Mon Sep 17 00:00:00 2001 From: Bing Sun Date: Tue, 19 Jul 2016 09:51:06 +0800 Subject: Staging: ks7010: michael_mic: fixed macros coding style issue Fixed coding style issue: Enclose multiple statements macros definition in a do while loop. Use one space around binary operators. Signed-off-by: Bing Sun Reviewed-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/ks7010/michael_mic.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/ks7010/michael_mic.c b/drivers/staging/ks7010/michael_mic.c index e14c109b3cab..d332678781d2 100644 --- a/drivers/staging/ks7010/michael_mic.c +++ b/drivers/staging/ks7010/michael_mic.c @@ -20,15 +20,21 @@ #define getUInt32( A, B ) (uint32_t)(A[B+0] << 0) + (A[B+1] << 8) + (A[B+2] << 16) + (A[B+3] << 24) // Convert from UInt32 to Byte[] in a portable way -#define putUInt32( A, B, C ) A[B+0] = (uint8_t) (C & 0xff); \ - A[B+1] = (uint8_t) ((C>>8) & 0xff); \ - A[B+2] = (uint8_t) ((C>>16) & 0xff); \ - A[B+3] = (uint8_t) ((C>>24) & 0xff) +#define putUInt32(A, B, C) \ +do { \ + A[B + 0] = (uint8_t)(C & 0xff); \ + A[B + 1] = (uint8_t)((C >> 8) & 0xff); \ + A[B + 2] = (uint8_t)((C >> 16) & 0xff); \ + A[B + 3] = (uint8_t)((C >> 24) & 0xff); \ +} while (0) // Reset the state to the empty message. -#define MichaelClear( A ) A->L = A->K0; \ - A->R = A->K1; \ - A->nBytesInM = 0; +#define MichaelClear(A) \ +do { \ + A->L = A->K0; \ + A->R = A->K1; \ + A->nBytesInM = 0; \ +} while (0) static void MichaelInitializeFunction(struct michel_mic_t *Mic, uint8_t * key) -- cgit v1.2.3 From 803394d03b43ba0ef4a9ed148de19c01d87cd13a Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Sat, 13 Aug 2016 19:52:38 +0100 Subject: staging: ks7010: do not dereference priv if priv is null priv is being dereferenced before a check for it being null is made, so there is a possibililty a null pointer deference can occur. Instead, only dereference priv if it is non-null. Signed-off-by: Colin Ian King Signed-off-by: Greg Kroah-Hartman --- drivers/staging/ks7010/ks7010_sdio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/ks7010/ks7010_sdio.c b/drivers/staging/ks7010/ks7010_sdio.c index a0facfc54e4b..47b69cbdb45b 100644 --- a/drivers/staging/ks7010/ks7010_sdio.c +++ b/drivers/staging/ks7010/ks7010_sdio.c @@ -1134,7 +1134,6 @@ static void ks7010_sdio_remove(struct sdio_func *func) int ret; struct ks_sdio_card *card; struct ks_wlan_private *priv; - struct net_device *netdev; DPRINTK(1, "ks7010_sdio_remove()\n"); card = sdio_get_drvdata(func); @@ -1144,8 +1143,9 @@ static void ks7010_sdio_remove(struct sdio_func *func) DPRINTK(1, "priv = card->priv\n"); priv = card->priv; - netdev = priv->net_dev; if (priv) { + struct net_device *netdev = priv->net_dev; + ks_wlan_net_stop(netdev); DPRINTK(1, "ks_wlan_net_stop\n"); -- cgit v1.2.3 From c7df077b6d6db8d3bed1d5de2707f3386198ae0d Mon Sep 17 00:00:00 2001 From: Laura Abbott Date: Mon, 8 Aug 2016 09:52:54 -0700 Subject: staging: android: ion: Get rid of ion_sg_table The ion_sg_table interface is mostly a reimplementation of what dma_buf is doing. Clients should be using dma_buf APIs instead. Signed-off-by: Laura Abbott Reviewed-by: Benjamin Gaignard Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/ion/ion.c | 20 -------------------- drivers/staging/android/ion/ion.h | 11 ----------- 2 files changed, 31 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index a2cf93b59016..95b18acc8695 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -917,26 +917,6 @@ void ion_client_destroy(struct ion_client *client) } EXPORT_SYMBOL(ion_client_destroy); -struct sg_table *ion_sg_table(struct ion_client *client, - struct ion_handle *handle) -{ - struct ion_buffer *buffer; - struct sg_table *table; - - mutex_lock(&client->lock); - if (!ion_handle_validate(client, handle)) { - pr_err("%s: invalid handle passed to map_dma.\n", - __func__); - mutex_unlock(&client->lock); - return ERR_PTR(-EINVAL); - } - buffer = handle->buffer; - table = buffer->sg_table; - mutex_unlock(&client->lock); - return table; -} -EXPORT_SYMBOL(ion_sg_table); - static void ion_buffer_sync_for_device(struct ion_buffer *buffer, struct device *dev, enum dma_data_direction direction); diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index a1331fc169a1..225c34a20c67 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -148,17 +148,6 @@ void ion_free(struct ion_client *client, struct ion_handle *handle); int ion_phys(struct ion_client *client, struct ion_handle *handle, ion_phys_addr_t *addr, size_t *len); -/** - * ion_map_dma - return an sg_table describing a handle - * @client: the client - * @handle: the handle - * - * This function returns the sg_table describing - * a particular ion handle. - */ -struct sg_table *ion_sg_table(struct ion_client *client, - struct ion_handle *handle); - /** * ion_map_kernel - create mapping for the given handle * @client: the client -- cgit v1.2.3 From da792ccb63d69abd0c6c84857666a086a38d1ef9 Mon Sep 17 00:00:00 2001 From: Laura Abbott Date: Mon, 8 Aug 2016 09:52:55 -0700 Subject: staging: android: ion: Drop ion_phys interface ion_phys was an interface used for older legacy behavior. sg_tables are the standard now. Get rid of it. Signed-off-by: Laura Abbott Reviewed-by: Benjamin Gaignard Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/ion/ion.c | 26 ------------------------- drivers/staging/android/ion/ion.h | 19 ------------------ drivers/staging/android/ion/ion_carveout_heap.c | 14 ------------- drivers/staging/android/ion/ion_cma_heap.c | 18 ----------------- drivers/staging/android/ion/ion_priv.h | 11 +---------- drivers/staging/android/ion/ion_system_heap.c | 12 ------------ 6 files changed, 1 insertion(+), 99 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 95b18acc8695..bcf113f60fb2 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -576,32 +576,6 @@ void ion_free(struct ion_client *client, struct ion_handle *handle) } EXPORT_SYMBOL(ion_free); -int ion_phys(struct ion_client *client, struct ion_handle *handle, - ion_phys_addr_t *addr, size_t *len) -{ - struct ion_buffer *buffer; - int ret; - - mutex_lock(&client->lock); - if (!ion_handle_validate(client, handle)) { - mutex_unlock(&client->lock); - return -EINVAL; - } - - buffer = handle->buffer; - - if (!buffer->heap->ops->phys) { - pr_err("%s: ion_phys is not implemented by this heap (name=%s, type=%d).\n", - __func__, buffer->heap->name, buffer->heap->type); - mutex_unlock(&client->lock); - return -ENODEV; - } - mutex_unlock(&client->lock); - ret = buffer->heap->ops->phys(buffer->heap, buffer, addr, len); - return ret; -} -EXPORT_SYMBOL(ion_phys); - static void *ion_buffer_kmap_get(struct ion_buffer *buffer) { void *vaddr; diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index 225c34a20c67..97eb7a72fa86 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -129,25 +129,6 @@ struct ion_handle *ion_alloc(struct ion_client *client, size_t len, */ void ion_free(struct ion_client *client, struct ion_handle *handle); -/** - * ion_phys - returns the physical address and len of a handle - * @client: the client - * @handle: the handle - * @addr: a pointer to put the address in - * @len: a pointer to put the length in - * - * This function queries the heap for a particular handle to get the - * handle's physical address. It't output is only correct if - * a heap returns physically contiguous memory -- in other cases - * this api should not be implemented -- ion_sg_table should be used - * instead. Returns -EINVAL if the handle is invalid. This has - * no implications on the reference counting of the handle -- - * the returned value may not be valid if the caller is not - * holding a reference. - */ -int ion_phys(struct ion_client *client, struct ion_handle *handle, - ion_phys_addr_t *addr, size_t *len); - /** * ion_map_kernel - create mapping for the given handle * @client: the client diff --git a/drivers/staging/android/ion/ion_carveout_heap.c b/drivers/staging/android/ion/ion_carveout_heap.c index 1fb0d81556da..25b969bc140d 100644 --- a/drivers/staging/android/ion/ion_carveout_heap.c +++ b/drivers/staging/android/ion/ion_carveout_heap.c @@ -56,19 +56,6 @@ void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr, gen_pool_free(carveout_heap->pool, addr, size); } -static int ion_carveout_heap_phys(struct ion_heap *heap, - struct ion_buffer *buffer, - ion_phys_addr_t *addr, size_t *len) -{ - struct sg_table *table = buffer->priv_virt; - struct page *page = sg_page(table->sgl); - ion_phys_addr_t paddr = PFN_PHYS(page_to_pfn(page)); - - *addr = paddr; - *len = buffer->size; - return 0; -} - static int ion_carveout_heap_allocate(struct ion_heap *heap, struct ion_buffer *buffer, unsigned long size, unsigned long align, @@ -138,7 +125,6 @@ static void ion_carveout_heap_unmap_dma(struct ion_heap *heap, static struct ion_heap_ops carveout_heap_ops = { .allocate = ion_carveout_heap_allocate, .free = ion_carveout_heap_free, - .phys = ion_carveout_heap_phys, .map_dma = ion_carveout_heap_map_dma, .unmap_dma = ion_carveout_heap_unmap_dma, .map_user = ion_heap_map_user, diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c index a3446da4fdc2..0828e333f2e7 100644 --- a/drivers/staging/android/ion/ion_cma_heap.c +++ b/drivers/staging/android/ion/ion_cma_heap.c @@ -105,23 +105,6 @@ static void ion_cma_free(struct ion_buffer *buffer) kfree(info); } -/* return physical address in addr */ -static int ion_cma_phys(struct ion_heap *heap, struct ion_buffer *buffer, - ion_phys_addr_t *addr, size_t *len) -{ - struct ion_cma_heap *cma_heap = to_cma_heap(buffer->heap); - struct device *dev = cma_heap->dev; - struct ion_cma_buffer_info *info = buffer->priv_virt; - - dev_dbg(dev, "Return buffer %p physical address %pa\n", buffer, - &info->handle); - - *addr = info->handle; - *len = buffer->size; - - return 0; -} - static struct sg_table *ion_cma_heap_map_dma(struct ion_heap *heap, struct ion_buffer *buffer) { @@ -164,7 +147,6 @@ static struct ion_heap_ops ion_cma_ops = { .free = ion_cma_free, .map_dma = ion_cma_heap_map_dma, .unmap_dma = ion_cma_heap_unmap_dma, - .phys = ion_cma_phys, .map_user = ion_cma_mmap, .map_kernel = ion_cma_map_kernel, .unmap_kernel = ion_cma_unmap_kernel, diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h index 0239883bffb7..141fb0d7b4cd 100644 --- a/drivers/staging/android/ion/ion_priv.h +++ b/drivers/staging/android/ion/ion_priv.h @@ -42,8 +42,6 @@ struct ion_buffer *ion_handle_buffer(struct ion_handle *handle); * @size: size of the buffer * @priv_virt: private data to the buffer representable as * a void * - * @priv_phys: private data to the buffer representable as - * an ion_phys_addr_t (and someday a phys_addr_t) * @lock: protects the buffers cnt fields * @kmap_cnt: number of times the buffer is mapped to the kernel * @vaddr: the kernel mapping if kmap_cnt is not zero @@ -69,10 +67,7 @@ struct ion_buffer { unsigned long flags; unsigned long private_flags; size_t size; - union { - void *priv_virt; - ion_phys_addr_t priv_phys; - }; + void *priv_virt; struct mutex lock; int kmap_cnt; void *vaddr; @@ -91,8 +86,6 @@ void ion_buffer_destroy(struct ion_buffer *buffer); * struct ion_heap_ops - ops to operate on a given heap * @allocate: allocate memory * @free: free memory - * @phys get physical address of a buffer (only define on - * physically contiguous heaps) * @map_dma map the memory for dma to a scatterlist * @unmap_dma unmap the memory for dma * @map_kernel map memory to the kernel @@ -111,8 +104,6 @@ struct ion_heap_ops { struct ion_buffer *buffer, unsigned long len, unsigned long align, unsigned long flags); void (*free)(struct ion_buffer *buffer); - int (*phys)(struct ion_heap *heap, struct ion_buffer *buffer, - ion_phys_addr_t *addr, size_t *len); struct sg_table * (*map_dma)(struct ion_heap *heap, struct ion_buffer *buffer); void (*unmap_dma)(struct ion_heap *heap, struct ion_buffer *buffer); diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index b69dfc706440..02bae94018af 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c @@ -386,17 +386,6 @@ static void ion_system_contig_heap_free(struct ion_buffer *buffer) kfree(table); } -static int ion_system_contig_heap_phys(struct ion_heap *heap, - struct ion_buffer *buffer, - ion_phys_addr_t *addr, size_t *len) -{ - struct sg_table *table = buffer->priv_virt; - struct page *page = sg_page(table->sgl); - *addr = page_to_phys(page); - *len = buffer->size; - return 0; -} - static struct sg_table *ion_system_contig_heap_map_dma(struct ion_heap *heap, struct ion_buffer *buffer) { @@ -411,7 +400,6 @@ static void ion_system_contig_heap_unmap_dma(struct ion_heap *heap, static struct ion_heap_ops kmalloc_ops = { .allocate = ion_system_contig_heap_allocate, .free = ion_system_contig_heap_free, - .phys = ion_system_contig_heap_phys, .map_dma = ion_system_contig_heap_map_dma, .unmap_dma = ion_system_contig_heap_unmap_dma, .map_kernel = ion_heap_map_kernel, -- cgit v1.2.3 From f82ad60e2b82c1efb48c3aa1eddbd516c7b2feea Mon Sep 17 00:00:00 2001 From: Laura Abbott Date: Mon, 8 Aug 2016 09:52:56 -0700 Subject: staging: android: ion: Get rid of map_dma/unmap_dma The map_dma API interface was designed to generate an sg_table. Currently, every client just creates the table at allocation time and then returns the one table. Nothing happens on unmap_dma either. Just get rid of the API and assign the sg_table directly. Signed-off-by: Laura Abbott Reviewed-by: Benjamin Gaignard Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/ion/ion.c | 23 +++++++----------- drivers/staging/android/ion/ion_carveout_heap.c | 17 ++----------- drivers/staging/android/ion/ion_chunk_heap.c | 17 ++----------- drivers/staging/android/ion/ion_cma_heap.c | 16 +------------ drivers/staging/android/ion/ion_priv.h | 5 ---- drivers/staging/android/ion/ion_system_heap.c | 32 +++---------------------- 6 files changed, 16 insertions(+), 94 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index bcf113f60fb2..cd730821cd6e 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -205,19 +205,16 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, goto err2; } - buffer->dev = dev; - buffer->size = len; - - table = heap->ops->map_dma(heap, buffer); - if (WARN_ONCE(table == NULL, - "heap->ops->map_dma should return ERR_PTR on error")) - table = ERR_PTR(-EINVAL); - if (IS_ERR(table)) { + if (buffer->sg_table == NULL) { + WARN_ONCE(1, "This heap needs to set the sgtable"); ret = -EINVAL; goto err1; } - buffer->sg_table = table; + table = buffer->sg_table; + buffer->dev = dev; + buffer->size = len; + if (ion_buffer_fault_user_mappings(buffer)) { int num_pages = PAGE_ALIGN(buffer->size) / PAGE_SIZE; struct scatterlist *sg; @@ -226,7 +223,7 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, buffer->pages = vmalloc(sizeof(struct page *) * num_pages); if (!buffer->pages) { ret = -ENOMEM; - goto err; + goto err1; } for_each_sg(table->sgl, sg, table->nents, i) { @@ -260,8 +257,6 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, mutex_unlock(&dev->buffer_lock); return buffer; -err: - heap->ops->unmap_dma(heap, buffer); err1: heap->ops->free(buffer); err2: @@ -273,7 +268,6 @@ void ion_buffer_destroy(struct ion_buffer *buffer) { if (WARN_ON(buffer->kmap_cnt > 0)) buffer->heap->ops->unmap_kernel(buffer->heap, buffer); - buffer->heap->ops->unmap_dma(buffer->heap, buffer); buffer->heap->ops->free(buffer); vfree(buffer->pages); kfree(buffer); @@ -1542,8 +1536,7 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap) { struct dentry *debug_file; - if (!heap->ops->allocate || !heap->ops->free || !heap->ops->map_dma || - !heap->ops->unmap_dma) + if (!heap->ops->allocate || !heap->ops->free) pr_err("%s: can not add heap with invalid ops struct.\n", __func__); diff --git a/drivers/staging/android/ion/ion_carveout_heap.c b/drivers/staging/android/ion/ion_carveout_heap.c index 25b969bc140d..cc2a3b8160bc 100644 --- a/drivers/staging/android/ion/ion_carveout_heap.c +++ b/drivers/staging/android/ion/ion_carveout_heap.c @@ -82,7 +82,7 @@ static int ion_carveout_heap_allocate(struct ion_heap *heap, } sg_set_page(table->sgl, pfn_to_page(PFN_DOWN(paddr)), size, 0); - buffer->priv_virt = table; + buffer->sg_table = table; return 0; @@ -96,7 +96,7 @@ err_free: static void ion_carveout_heap_free(struct ion_buffer *buffer) { struct ion_heap *heap = buffer->heap; - struct sg_table *table = buffer->priv_virt; + struct sg_table *table = buffer->sg_table; struct page *page = sg_page(table->sgl); ion_phys_addr_t paddr = PFN_PHYS(page_to_pfn(page)); @@ -111,22 +111,9 @@ static void ion_carveout_heap_free(struct ion_buffer *buffer) kfree(table); } -static struct sg_table *ion_carveout_heap_map_dma(struct ion_heap *heap, - struct ion_buffer *buffer) -{ - return buffer->priv_virt; -} - -static void ion_carveout_heap_unmap_dma(struct ion_heap *heap, - struct ion_buffer *buffer) -{ -} - static struct ion_heap_ops carveout_heap_ops = { .allocate = ion_carveout_heap_allocate, .free = ion_carveout_heap_free, - .map_dma = ion_carveout_heap_map_dma, - .unmap_dma = ion_carveout_heap_unmap_dma, .map_user = ion_heap_map_user, .map_kernel = ion_heap_map_kernel, .unmap_kernel = ion_heap_unmap_kernel, diff --git a/drivers/staging/android/ion/ion_chunk_heap.c b/drivers/staging/android/ion/ion_chunk_heap.c index e0553fee9b8a..560cf907aed5 100644 --- a/drivers/staging/android/ion/ion_chunk_heap.c +++ b/drivers/staging/android/ion/ion_chunk_heap.c @@ -75,7 +75,7 @@ static int ion_chunk_heap_allocate(struct ion_heap *heap, sg = sg_next(sg); } - buffer->priv_virt = table; + buffer->sg_table = table; chunk_heap->allocated += allocated_size; return 0; err: @@ -95,7 +95,7 @@ static void ion_chunk_heap_free(struct ion_buffer *buffer) struct ion_heap *heap = buffer->heap; struct ion_chunk_heap *chunk_heap = container_of(heap, struct ion_chunk_heap, heap); - struct sg_table *table = buffer->priv_virt; + struct sg_table *table = buffer->sg_table; struct scatterlist *sg; int i; unsigned long allocated_size; @@ -117,22 +117,9 @@ static void ion_chunk_heap_free(struct ion_buffer *buffer) kfree(table); } -static struct sg_table *ion_chunk_heap_map_dma(struct ion_heap *heap, - struct ion_buffer *buffer) -{ - return buffer->priv_virt; -} - -static void ion_chunk_heap_unmap_dma(struct ion_heap *heap, - struct ion_buffer *buffer) -{ -} - static struct ion_heap_ops chunk_heap_ops = { .allocate = ion_chunk_heap_allocate, .free = ion_chunk_heap_free, - .map_dma = ion_chunk_heap_map_dma, - .unmap_dma = ion_chunk_heap_unmap_dma, .map_user = ion_heap_map_user, .map_kernel = ion_heap_map_kernel, .unmap_kernel = ion_heap_unmap_kernel, diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c index 0828e333f2e7..d5ff3a282dfd 100644 --- a/drivers/staging/android/ion/ion_cma_heap.c +++ b/drivers/staging/android/ion/ion_cma_heap.c @@ -78,6 +78,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer, goto free_table; /* keep this for memory release */ buffer->priv_virt = info; + buffer->sg_table = info->table; dev_dbg(dev, "Allocate buffer %p\n", buffer); return 0; @@ -105,19 +106,6 @@ static void ion_cma_free(struct ion_buffer *buffer) kfree(info); } -static struct sg_table *ion_cma_heap_map_dma(struct ion_heap *heap, - struct ion_buffer *buffer) -{ - struct ion_cma_buffer_info *info = buffer->priv_virt; - - return info->table; -} - -static void ion_cma_heap_unmap_dma(struct ion_heap *heap, - struct ion_buffer *buffer) -{ -} - static int ion_cma_mmap(struct ion_heap *mapper, struct ion_buffer *buffer, struct vm_area_struct *vma) { @@ -145,8 +133,6 @@ static void ion_cma_unmap_kernel(struct ion_heap *heap, static struct ion_heap_ops ion_cma_ops = { .allocate = ion_cma_allocate, .free = ion_cma_free, - .map_dma = ion_cma_heap_map_dma, - .unmap_dma = ion_cma_heap_unmap_dma, .map_user = ion_cma_mmap, .map_kernel = ion_cma_map_kernel, .unmap_kernel = ion_cma_unmap_kernel, diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h index 141fb0d7b4cd..3dd91172540b 100644 --- a/drivers/staging/android/ion/ion_priv.h +++ b/drivers/staging/android/ion/ion_priv.h @@ -86,8 +86,6 @@ void ion_buffer_destroy(struct ion_buffer *buffer); * struct ion_heap_ops - ops to operate on a given heap * @allocate: allocate memory * @free: free memory - * @map_dma map the memory for dma to a scatterlist - * @unmap_dma unmap the memory for dma * @map_kernel map memory to the kernel * @unmap_kernel unmap memory to the kernel * @map_user map memory to userspace @@ -104,9 +102,6 @@ struct ion_heap_ops { struct ion_buffer *buffer, unsigned long len, unsigned long align, unsigned long flags); void (*free)(struct ion_buffer *buffer); - struct sg_table * (*map_dma)(struct ion_heap *heap, - struct ion_buffer *buffer); - void (*unmap_dma)(struct ion_heap *heap, struct ion_buffer *buffer); void * (*map_kernel)(struct ion_heap *heap, struct ion_buffer *buffer); void (*unmap_kernel)(struct ion_heap *heap, struct ion_buffer *buffer); int (*map_user)(struct ion_heap *mapper, struct ion_buffer *buffer, diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index 02bae94018af..b697c6da0c3a 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c @@ -164,7 +164,7 @@ static int ion_system_heap_allocate(struct ion_heap *heap, list_del(&page->lru); } - buffer->priv_virt = table; + buffer->sg_table = table; return 0; free_table: @@ -199,17 +199,6 @@ static void ion_system_heap_free(struct ion_buffer *buffer) kfree(table); } -static struct sg_table *ion_system_heap_map_dma(struct ion_heap *heap, - struct ion_buffer *buffer) -{ - return buffer->priv_virt; -} - -static void ion_system_heap_unmap_dma(struct ion_heap *heap, - struct ion_buffer *buffer) -{ -} - static int ion_system_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask, int nr_to_scan) { @@ -243,8 +232,6 @@ static int ion_system_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask, static struct ion_heap_ops system_heap_ops = { .allocate = ion_system_heap_allocate, .free = ion_system_heap_free, - .map_dma = ion_system_heap_map_dma, - .unmap_dma = ion_system_heap_unmap_dma, .map_kernel = ion_heap_map_kernel, .unmap_kernel = ion_heap_unmap_kernel, .map_user = ion_heap_map_user, @@ -358,7 +345,7 @@ static int ion_system_contig_heap_allocate(struct ion_heap *heap, sg_set_page(table->sgl, page, len, 0); - buffer->priv_virt = table; + buffer->sg_table = table; ion_pages_sync_for_device(NULL, page, len, DMA_BIDIRECTIONAL); @@ -375,7 +362,7 @@ free_pages: static void ion_system_contig_heap_free(struct ion_buffer *buffer) { - struct sg_table *table = buffer->priv_virt; + struct sg_table *table = buffer->sg_table; struct page *page = sg_page(table->sgl); unsigned long pages = PAGE_ALIGN(buffer->size) >> PAGE_SHIFT; unsigned long i; @@ -386,22 +373,9 @@ static void ion_system_contig_heap_free(struct ion_buffer *buffer) kfree(table); } -static struct sg_table *ion_system_contig_heap_map_dma(struct ion_heap *heap, - struct ion_buffer *buffer) -{ - return buffer->priv_virt; -} - -static void ion_system_contig_heap_unmap_dma(struct ion_heap *heap, - struct ion_buffer *buffer) -{ -} - static struct ion_heap_ops kmalloc_ops = { .allocate = ion_system_contig_heap_allocate, .free = ion_system_contig_heap_free, - .map_dma = ion_system_contig_heap_map_dma, - .unmap_dma = ion_system_contig_heap_unmap_dma, .map_kernel = ion_heap_map_kernel, .unmap_kernel = ion_heap_unmap_kernel, .map_user = ion_heap_map_user, -- cgit v1.2.3 From 0ba5aa477f42c45e2057eb5d3eaa408d0dffec74 Mon Sep 17 00:00:00 2001 From: Laura Abbott Date: Mon, 8 Aug 2016 09:52:57 -0700 Subject: staging: android: ion: Drop ion_carveout_allocate definitions ion_carveout_allocate and ion_carveout_free aren't used outside of the carveout heap. Get rid of the definitions. Signed-off-by: Laura Abbott Reviewed-by: Benjamin Gaignard Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/ion/ion_carveout_heap.c | 2 ++ drivers/staging/android/ion/ion_priv.h | 14 -------------- 2 files changed, 2 insertions(+), 14 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/android/ion/ion_carveout_heap.c b/drivers/staging/android/ion/ion_carveout_heap.c index cc2a3b8160bc..c4f0795fb62e 100644 --- a/drivers/staging/android/ion/ion_carveout_heap.c +++ b/drivers/staging/android/ion/ion_carveout_heap.c @@ -25,6 +25,8 @@ #include "ion.h" #include "ion_priv.h" +#define ION_CARVEOUT_ALLOCATE_FAIL -1 + struct ion_carveout_heap { struct ion_heap heap; struct gen_pool *pool; diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h index 3dd91172540b..25e4bb2dac87 100644 --- a/drivers/staging/android/ion/ion_priv.h +++ b/drivers/staging/android/ion/ion_priv.h @@ -313,20 +313,6 @@ void ion_chunk_heap_destroy(struct ion_heap *); struct ion_heap *ion_cma_heap_create(struct ion_platform_heap *); void ion_cma_heap_destroy(struct ion_heap *); -/** - * kernel api to allocate/free from carveout -- used when carveout is - * used to back an architecture specific custom heap - */ -ion_phys_addr_t ion_carveout_allocate(struct ion_heap *heap, unsigned long size, - unsigned long align); -void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr, - unsigned long size); -/** - * The carveout heap returns physical addresses, since 0 may be a valid - * physical address, this is used to indicate allocation failed - */ -#define ION_CARVEOUT_ALLOCATE_FAIL -1 - /** * functions for creating and destroying a heap pool -- allows you * to keep a pool of pre allocated memory to use from your heap. Keeping -- cgit v1.2.3 From 04b8290f3b95a3935ed07f2954bad9c87e8fb143 Mon Sep 17 00:00:00 2001 From: Laura Abbott Date: Mon, 8 Aug 2016 09:52:58 -0700 Subject: staging: android: ion: Get rid of ion_reserve ion_reserve was supposed to be used to reserve memory in board files. These days, board files are no more and there are other more controlled mechanisms for reserving memory. Get rid of this function. Signed-off-by: Laura Abbott Reviewed-by: Benjamin Gaignard Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/ion/ion.c | 34 ---------------------------------- drivers/staging/android/ion/ion.h | 11 ----------- 2 files changed, 45 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index cd730821cd6e..7138a5b2bb10 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -1650,37 +1650,3 @@ void ion_device_destroy(struct ion_device *dev) } EXPORT_SYMBOL(ion_device_destroy); -void __init ion_reserve(struct ion_platform_data *data) -{ - int i; - - for (i = 0; i < data->nr; i++) { - if (data->heaps[i].size == 0) - continue; - - if (data->heaps[i].base == 0) { - phys_addr_t paddr; - - paddr = memblock_alloc_base(data->heaps[i].size, - data->heaps[i].align, - MEMBLOCK_ALLOC_ANYWHERE); - if (!paddr) { - pr_err("%s: error allocating memblock for heap %d\n", - __func__, i); - continue; - } - data->heaps[i].base = paddr; - } else { - int ret = memblock_reserve(data->heaps[i].base, - data->heaps[i].size); - if (ret) - pr_err("memblock reserve of %zx@%lx failed\n", - data->heaps[i].size, - data->heaps[i].base); - } - pr_info("%s: %s reserved base %lx size %zu\n", __func__, - data->heaps[i].name, - data->heaps[i].base, - data->heaps[i].size); - } -} diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index 97eb7a72fa86..93dafb4586e4 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -72,17 +72,6 @@ struct ion_platform_data { struct ion_platform_heap *heaps; }; -/** - * ion_reserve() - reserve memory for ion heaps if applicable - * @data: platform data specifying starting physical address and - * size - * - * Calls memblock reserve to set aside memory for heaps that are - * located at specific memory addresses or of specific sizes not - * managed by the kernel - */ -void ion_reserve(struct ion_platform_data *data); - /** * ion_client_create() - allocate a client and returns it * @dev: the global ion device -- cgit v1.2.3 From a4ebee657c9be3afd35530cd4478b0fa514706d7 Mon Sep 17 00:00:00 2001 From: Gustavo Padovan Date: Thu, 11 Aug 2016 12:26:40 -0300 Subject: staging/android: do not let userspace trigger WARN_ON Closing the timeline without waiting all fences to signal is not a critical failure, it is just bad usage from userspace so avoid calling WARN_ON in this case. Signed-off-by: Gustavo Padovan Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/sw_sync.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/staging') diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c index 115c9174705f..bda1f6a220c1 100644 --- a/drivers/staging/android/sw_sync.c +++ b/drivers/staging/android/sw_sync.c @@ -176,7 +176,7 @@ static void timeline_fence_release(struct fence *fence) spin_lock_irqsave(fence->lock, flags); list_del(&pt->child_list); - if (WARN_ON_ONCE(!list_empty(&pt->active_list))) + if (!list_empty(&pt->active_list)) list_del(&pt->active_list); spin_unlock_irqrestore(fence->lock, flags); -- cgit v1.2.3 From a04f915eba944d41773146bb6c004212b29a6ace Mon Sep 17 00:00:00 2001 From: Gustavo Padovan Date: Thu, 11 Aug 2016 12:26:41 -0300 Subject: staging/android: move trace/sync.h to sync_trace.h The common behaviour for trace headers is to have them in the same folder they are used, instead of creating a special trace/ directory. Signed-off-by: Gustavo Padovan Reviewed-by: Eric Engestrom Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/sw_sync.c | 2 +- drivers/staging/android/sync_trace.h | 32 ++++++++++++++++++++++++++++++++ drivers/staging/android/trace/sync.h | 32 -------------------------------- 3 files changed, 33 insertions(+), 33 deletions(-) create mode 100644 drivers/staging/android/sync_trace.h delete mode 100644 drivers/staging/android/trace/sync.h (limited to 'drivers/staging') diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c index bda1f6a220c1..92c1f8b1fd85 100644 --- a/drivers/staging/android/sw_sync.c +++ b/drivers/staging/android/sw_sync.c @@ -23,7 +23,7 @@ #include "sync_debug.h" #define CREATE_TRACE_POINTS -#include "trace/sync.h" +#include "sync_trace.h" struct sw_sync_create_fence_data { __u32 value; diff --git a/drivers/staging/android/sync_trace.h b/drivers/staging/android/sync_trace.h new file mode 100644 index 000000000000..ea485f7be58a --- /dev/null +++ b/drivers/staging/android/sync_trace.h @@ -0,0 +1,32 @@ +#undef TRACE_SYSTEM +#define TRACE_INCLUDE_PATH ../../drivers/staging/android +#define TRACE_SYSTEM sync_trace + +#if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_SYNC_H + +#include "sync_debug.h" +#include + +TRACE_EVENT(sync_timeline, + TP_PROTO(struct sync_timeline *timeline), + + TP_ARGS(timeline), + + TP_STRUCT__entry( + __string(name, timeline->name) + __field(u32, value) + ), + + TP_fast_assign( + __assign_str(name, timeline->name); + __entry->value = timeline->value; + ), + + TP_printk("name=%s value=%d", __get_str(name), __entry->value) +); + +#endif /* if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ) */ + +/* This part must be outside protection */ +#include diff --git a/drivers/staging/android/trace/sync.h b/drivers/staging/android/trace/sync.h deleted file mode 100644 index 6b5ce9640ddd..000000000000 --- a/drivers/staging/android/trace/sync.h +++ /dev/null @@ -1,32 +0,0 @@ -#undef TRACE_SYSTEM -#define TRACE_INCLUDE_PATH ../../drivers/staging/android/trace -#define TRACE_SYSTEM sync - -#if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ) -#define _TRACE_SYNC_H - -#include "../sync_debug.h" -#include - -TRACE_EVENT(sync_timeline, - TP_PROTO(struct sync_timeline *timeline), - - TP_ARGS(timeline), - - TP_STRUCT__entry( - __string(name, timeline->name) - __field(u32, value) - ), - - TP_fast_assign( - __assign_str(name, timeline->name); - __entry->value = timeline->value; - ), - - TP_printk("name=%s value=%d", __get_str(name), __entry->value) -); - -#endif /* if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ) */ - -/* This part must be outside protection */ -#include -- cgit v1.2.3 From e912c881f13523fa696f5a7233ee3fffc66fa6a3 Mon Sep 17 00:00:00 2001 From: Gustavo Padovan Date: Thu, 11 Aug 2016 12:26:42 -0300 Subject: staging/android: prepare sw_sync files for de-staging remove file paths in the comments and add short description about each file. v2: remove file paths instead of just change them. v3: improve header description as sugggested by Eric Signed-off-by: Gustavo Padovan Reviewed-by: Eric Engestrom Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/sw_sync.c | 2 +- drivers/staging/android/sync_debug.c | 2 +- drivers/staging/android/sync_debug.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c index 92c1f8b1fd85..039e1f48855f 100644 --- a/drivers/staging/android/sw_sync.c +++ b/drivers/staging/android/sw_sync.c @@ -1,5 +1,5 @@ /* - * drivers/dma-buf/sw_sync.c + * Sync File validation framework * * Copyright (C) 2012 Google, Inc. * diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c index 4c5a85595a85..fab95204cf74 100644 --- a/drivers/staging/android/sync_debug.c +++ b/drivers/staging/android/sync_debug.c @@ -1,5 +1,5 @@ /* - * drivers/base/sync.c + * Sync File validation framework and debug information * * Copyright (C) 2012 Google, Inc. * diff --git a/drivers/staging/android/sync_debug.h b/drivers/staging/android/sync_debug.h index fab66396d421..d269aa6783aa 100644 --- a/drivers/staging/android/sync_debug.h +++ b/drivers/staging/android/sync_debug.h @@ -1,5 +1,5 @@ /* - * include/linux/sync.h + * Sync File validation framework and debug infomation * * Copyright (C) 2012 Google, Inc. * -- cgit v1.2.3 From fc0c9a03b57efb769a74fa8b33d68d90153b5950 Mon Sep 17 00:00:00 2001 From: Gustavo Padovan Date: Thu, 11 Aug 2016 13:45:53 -0300 Subject: staging/android: add Doc for SW_SYNC ioctl interface This interface is hidden from kernel headers and it is intended for use only for testing. So testers would have to add the ioctl information internally. This is to prevent misuse of this feature. v2: take in Eric suggestions for the Documentation v3: really take in Eric suggestions Signed-off-by: Gustavo Padovan Reviewed-by: Eric Engestrom Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/sw_sync.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'drivers/staging') diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c index 039e1f48855f..62e8e6dc7953 100644 --- a/drivers/staging/android/sw_sync.c +++ b/drivers/staging/android/sw_sync.c @@ -25,6 +25,36 @@ #define CREATE_TRACE_POINTS #include "sync_trace.h" +/* + * SW SYNC validation framework + * + * A sync object driver that uses a 32bit counter to coordinate + * synchronization. Useful when there is no hardware primitive backing + * the synchronization. + * + * To start the framework just open: + * + * /sync/sw_sync + * + * That will create a sync timeline, all fences created under this timeline + * file descriptor will belong to the this timeline. + * + * The 'sw_sync' file can be opened many times as to create different + * timelines. + * + * Fences can be created with SW_SYNC_IOC_CREATE_FENCE ioctl with struct + * sw_sync_ioctl_create_fence as parameter. + * + * To increment the timeline counter, SW_SYNC_IOC_INC ioctl should be used + * with the increment as u32. This will update the last signaled value + * from the timeline and signal any fence that has a seqno smaller or equal + * to it. + * + * struct sw_sync_ioctl_create_fence + * @value: the seqno to initialise the fence with + * @name: the name of the new sync point + * @fence: return the fd of the new sync_file with the created fence + */ struct sw_sync_create_fence_data { __u32 value; char name[32]; @@ -35,6 +65,7 @@ struct sw_sync_create_fence_data { #define SW_SYNC_IOC_CREATE_FENCE _IOWR(SW_SYNC_IOC_MAGIC, 0,\ struct sw_sync_create_fence_data) + #define SW_SYNC_IOC_INC _IOW(SW_SYNC_IOC_MAGIC, 1, __u32) static const struct fence_ops timeline_fence_ops; -- cgit v1.2.3 From 35538d7822e86cb38015c21bb708a433f8814af0 Mon Sep 17 00:00:00 2001 From: Gustavo Padovan Date: Thu, 11 Aug 2016 12:26:44 -0300 Subject: dma-buf/sw_sync: de-stage SW_SYNC SW_SYNC allows to run tests on the sync_file framework via debugfs on /sync/sw_sync Opening and closing the file triggers creation and release of a sync timeline. To create fences on this timeline the SW_SYNC_IOC_CREATE_FENCE ioctl should be used. To increment the timeline value use SW_SYNC_IOC_INC. Also it exports Sync information on /sync/info Signed-off-by: Gustavo Padovan Reviewed-by: Eric Engestrom Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/Kconfig | 13 -- drivers/staging/android/Makefile | 1 - drivers/staging/android/sw_sync.c | 375 ----------------------------------- drivers/staging/android/sync_debug.c | 230 --------------------- drivers/staging/android/sync_debug.h | 84 -------- drivers/staging/android/sync_trace.h | 32 --- 6 files changed, 735 deletions(-) delete mode 100644 drivers/staging/android/sw_sync.c delete mode 100644 drivers/staging/android/sync_debug.c delete mode 100644 drivers/staging/android/sync_debug.h delete mode 100644 drivers/staging/android/sync_trace.h (limited to 'drivers/staging') diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig index 06e41d24ec62..6c00d6f765c6 100644 --- a/drivers/staging/android/Kconfig +++ b/drivers/staging/android/Kconfig @@ -24,19 +24,6 @@ config ANDROID_LOW_MEMORY_KILLER scripts (/init.rc), and it defines priority values with minimum free memory size for each priority. -config SW_SYNC - bool "Software synchronization framework" - default n - depends on SYNC_FILE - depends on DEBUG_FS - ---help--- - A sync object driver that uses a 32bit counter to coordinate - synchronization. Useful when there is no hardware primitive backing - the synchronization. - - WARNING: improper use of this can result in deadlocking kernel - drivers from userspace. Intended for test and debug only. - source "drivers/staging/android/ion/Kconfig" endif # if ANDROID diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile index 7ca61b77a8d4..7ed1be798909 100644 --- a/drivers/staging/android/Makefile +++ b/drivers/staging/android/Makefile @@ -4,4 +4,3 @@ obj-y += ion/ obj-$(CONFIG_ASHMEM) += ashmem.o obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER) += lowmemorykiller.o -obj-$(CONFIG_SW_SYNC) += sw_sync.o sync_debug.o diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c deleted file mode 100644 index 62e8e6dc7953..000000000000 --- a/drivers/staging/android/sw_sync.c +++ /dev/null @@ -1,375 +0,0 @@ -/* - * Sync File validation framework - * - * Copyright (C) 2012 Google, Inc. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -#include -#include -#include -#include -#include - -#include "sync_debug.h" - -#define CREATE_TRACE_POINTS -#include "sync_trace.h" - -/* - * SW SYNC validation framework - * - * A sync object driver that uses a 32bit counter to coordinate - * synchronization. Useful when there is no hardware primitive backing - * the synchronization. - * - * To start the framework just open: - * - * /sync/sw_sync - * - * That will create a sync timeline, all fences created under this timeline - * file descriptor will belong to the this timeline. - * - * The 'sw_sync' file can be opened many times as to create different - * timelines. - * - * Fences can be created with SW_SYNC_IOC_CREATE_FENCE ioctl with struct - * sw_sync_ioctl_create_fence as parameter. - * - * To increment the timeline counter, SW_SYNC_IOC_INC ioctl should be used - * with the increment as u32. This will update the last signaled value - * from the timeline and signal any fence that has a seqno smaller or equal - * to it. - * - * struct sw_sync_ioctl_create_fence - * @value: the seqno to initialise the fence with - * @name: the name of the new sync point - * @fence: return the fd of the new sync_file with the created fence - */ -struct sw_sync_create_fence_data { - __u32 value; - char name[32]; - __s32 fence; /* fd of new fence */ -}; - -#define SW_SYNC_IOC_MAGIC 'W' - -#define SW_SYNC_IOC_CREATE_FENCE _IOWR(SW_SYNC_IOC_MAGIC, 0,\ - struct sw_sync_create_fence_data) - -#define SW_SYNC_IOC_INC _IOW(SW_SYNC_IOC_MAGIC, 1, __u32) - -static const struct fence_ops timeline_fence_ops; - -static inline struct sync_pt *fence_to_sync_pt(struct fence *fence) -{ - if (fence->ops != &timeline_fence_ops) - return NULL; - return container_of(fence, struct sync_pt, base); -} - -/** - * sync_timeline_create() - creates a sync object - * @name: sync_timeline name - * - * Creates a new sync_timeline. Returns the sync_timeline object or NULL in - * case of error. - */ -struct sync_timeline *sync_timeline_create(const char *name) -{ - struct sync_timeline *obj; - - obj = kzalloc(sizeof(*obj), GFP_KERNEL); - if (!obj) - return NULL; - - kref_init(&obj->kref); - obj->context = fence_context_alloc(1); - strlcpy(obj->name, name, sizeof(obj->name)); - - INIT_LIST_HEAD(&obj->child_list_head); - INIT_LIST_HEAD(&obj->active_list_head); - spin_lock_init(&obj->child_list_lock); - - sync_timeline_debug_add(obj); - - return obj; -} - -static void sync_timeline_free(struct kref *kref) -{ - struct sync_timeline *obj = - container_of(kref, struct sync_timeline, kref); - - sync_timeline_debug_remove(obj); - - kfree(obj); -} - -static void sync_timeline_get(struct sync_timeline *obj) -{ - kref_get(&obj->kref); -} - -static void sync_timeline_put(struct sync_timeline *obj) -{ - kref_put(&obj->kref, sync_timeline_free); -} - -/** - * sync_timeline_signal() - signal a status change on a sync_timeline - * @obj: sync_timeline to signal - * @inc: num to increment on timeline->value - * - * A sync implementation should call this any time one of it's fences - * has signaled or has an error condition. - */ -static void sync_timeline_signal(struct sync_timeline *obj, unsigned int inc) -{ - unsigned long flags; - struct sync_pt *pt, *next; - - trace_sync_timeline(obj); - - spin_lock_irqsave(&obj->child_list_lock, flags); - - obj->value += inc; - - list_for_each_entry_safe(pt, next, &obj->active_list_head, - active_list) { - if (fence_is_signaled_locked(&pt->base)) - list_del_init(&pt->active_list); - } - - spin_unlock_irqrestore(&obj->child_list_lock, flags); -} - -/** - * sync_pt_create() - creates a sync pt - * @parent: fence's parent sync_timeline - * @size: size to allocate for this pt - * @inc: value of the fence - * - * Creates a new sync_pt as a child of @parent. @size bytes will be - * allocated allowing for implementation specific data to be kept after - * the generic sync_timeline struct. Returns the sync_pt object or - * NULL in case of error. - */ -static struct sync_pt *sync_pt_create(struct sync_timeline *obj, int size, - unsigned int value) -{ - unsigned long flags; - struct sync_pt *pt; - - if (size < sizeof(*pt)) - return NULL; - - pt = kzalloc(size, GFP_KERNEL); - if (!pt) - return NULL; - - spin_lock_irqsave(&obj->child_list_lock, flags); - sync_timeline_get(obj); - fence_init(&pt->base, &timeline_fence_ops, &obj->child_list_lock, - obj->context, value); - list_add_tail(&pt->child_list, &obj->child_list_head); - INIT_LIST_HEAD(&pt->active_list); - spin_unlock_irqrestore(&obj->child_list_lock, flags); - return pt; -} - -static const char *timeline_fence_get_driver_name(struct fence *fence) -{ - return "sw_sync"; -} - -static const char *timeline_fence_get_timeline_name(struct fence *fence) -{ - struct sync_timeline *parent = fence_parent(fence); - - return parent->name; -} - -static void timeline_fence_release(struct fence *fence) -{ - struct sync_pt *pt = fence_to_sync_pt(fence); - struct sync_timeline *parent = fence_parent(fence); - unsigned long flags; - - spin_lock_irqsave(fence->lock, flags); - list_del(&pt->child_list); - if (!list_empty(&pt->active_list)) - list_del(&pt->active_list); - spin_unlock_irqrestore(fence->lock, flags); - - sync_timeline_put(parent); - fence_free(fence); -} - -static bool timeline_fence_signaled(struct fence *fence) -{ - struct sync_timeline *parent = fence_parent(fence); - - return (fence->seqno > parent->value) ? false : true; -} - -static bool timeline_fence_enable_signaling(struct fence *fence) -{ - struct sync_pt *pt = fence_to_sync_pt(fence); - struct sync_timeline *parent = fence_parent(fence); - - if (timeline_fence_signaled(fence)) - return false; - - list_add_tail(&pt->active_list, &parent->active_list_head); - return true; -} - -static void timeline_fence_value_str(struct fence *fence, - char *str, int size) -{ - snprintf(str, size, "%d", fence->seqno); -} - -static void timeline_fence_timeline_value_str(struct fence *fence, - char *str, int size) -{ - struct sync_timeline *parent = fence_parent(fence); - - snprintf(str, size, "%d", parent->value); -} - -static const struct fence_ops timeline_fence_ops = { - .get_driver_name = timeline_fence_get_driver_name, - .get_timeline_name = timeline_fence_get_timeline_name, - .enable_signaling = timeline_fence_enable_signaling, - .signaled = timeline_fence_signaled, - .wait = fence_default_wait, - .release = timeline_fence_release, - .fence_value_str = timeline_fence_value_str, - .timeline_value_str = timeline_fence_timeline_value_str, -}; - -/* - * *WARNING* - * - * improper use of this can result in deadlocking kernel drivers from userspace. - */ - -/* opening sw_sync create a new sync obj */ -static int sw_sync_debugfs_open(struct inode *inode, struct file *file) -{ - struct sync_timeline *obj; - char task_comm[TASK_COMM_LEN]; - - get_task_comm(task_comm, current); - - obj = sync_timeline_create(task_comm); - if (!obj) - return -ENOMEM; - - file->private_data = obj; - - return 0; -} - -static int sw_sync_debugfs_release(struct inode *inode, struct file *file) -{ - struct sync_timeline *obj = file->private_data; - - smp_wmb(); - - sync_timeline_put(obj); - return 0; -} - -static long sw_sync_ioctl_create_fence(struct sync_timeline *obj, - unsigned long arg) -{ - int fd = get_unused_fd_flags(O_CLOEXEC); - int err; - struct sync_pt *pt; - struct sync_file *sync_file; - struct sw_sync_create_fence_data data; - - if (fd < 0) - return fd; - - if (copy_from_user(&data, (void __user *)arg, sizeof(data))) { - err = -EFAULT; - goto err; - } - - pt = sync_pt_create(obj, sizeof(*pt), data.value); - if (!pt) { - err = -ENOMEM; - goto err; - } - - sync_file = sync_file_create(&pt->base); - if (!sync_file) { - fence_put(&pt->base); - err = -ENOMEM; - goto err; - } - - data.fence = fd; - if (copy_to_user((void __user *)arg, &data, sizeof(data))) { - fput(sync_file->file); - err = -EFAULT; - goto err; - } - - fd_install(fd, sync_file->file); - - return 0; - -err: - put_unused_fd(fd); - return err; -} - -static long sw_sync_ioctl_inc(struct sync_timeline *obj, unsigned long arg) -{ - u32 value; - - if (copy_from_user(&value, (void __user *)arg, sizeof(value))) - return -EFAULT; - - sync_timeline_signal(obj, value); - - return 0; -} - -static long sw_sync_ioctl(struct file *file, unsigned int cmd, - unsigned long arg) -{ - struct sync_timeline *obj = file->private_data; - - switch (cmd) { - case SW_SYNC_IOC_CREATE_FENCE: - return sw_sync_ioctl_create_fence(obj, arg); - - case SW_SYNC_IOC_INC: - return sw_sync_ioctl_inc(obj, arg); - - default: - return -ENOTTY; - } -} - -const struct file_operations sw_sync_debugfs_fops = { - .open = sw_sync_debugfs_open, - .release = sw_sync_debugfs_release, - .unlocked_ioctl = sw_sync_ioctl, - .compat_ioctl = sw_sync_ioctl, -}; diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c deleted file mode 100644 index fab95204cf74..000000000000 --- a/drivers/staging/android/sync_debug.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Sync File validation framework and debug information - * - * Copyright (C) 2012 Google, Inc. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -#include -#include "sync_debug.h" - -static struct dentry *dbgfs; - -static LIST_HEAD(sync_timeline_list_head); -static DEFINE_SPINLOCK(sync_timeline_list_lock); -static LIST_HEAD(sync_file_list_head); -static DEFINE_SPINLOCK(sync_file_list_lock); - -void sync_timeline_debug_add(struct sync_timeline *obj) -{ - unsigned long flags; - - spin_lock_irqsave(&sync_timeline_list_lock, flags); - list_add_tail(&obj->sync_timeline_list, &sync_timeline_list_head); - spin_unlock_irqrestore(&sync_timeline_list_lock, flags); -} - -void sync_timeline_debug_remove(struct sync_timeline *obj) -{ - unsigned long flags; - - spin_lock_irqsave(&sync_timeline_list_lock, flags); - list_del(&obj->sync_timeline_list); - spin_unlock_irqrestore(&sync_timeline_list_lock, flags); -} - -void sync_file_debug_add(struct sync_file *sync_file) -{ - unsigned long flags; - - spin_lock_irqsave(&sync_file_list_lock, flags); - list_add_tail(&sync_file->sync_file_list, &sync_file_list_head); - spin_unlock_irqrestore(&sync_file_list_lock, flags); -} - -void sync_file_debug_remove(struct sync_file *sync_file) -{ - unsigned long flags; - - spin_lock_irqsave(&sync_file_list_lock, flags); - list_del(&sync_file->sync_file_list); - spin_unlock_irqrestore(&sync_file_list_lock, flags); -} - -static const char *sync_status_str(int status) -{ - if (status == 0) - return "signaled"; - - if (status > 0) - return "active"; - - return "error"; -} - -static void sync_print_fence(struct seq_file *s, struct fence *fence, bool show) -{ - int status = 1; - struct sync_timeline *parent = fence_parent(fence); - - if (fence_is_signaled_locked(fence)) - status = fence->status; - - seq_printf(s, " %s%sfence %s", - show ? parent->name : "", - show ? "_" : "", - sync_status_str(status)); - - if (status <= 0) { - struct timespec64 ts64 = - ktime_to_timespec64(fence->timestamp); - - seq_printf(s, "@%lld.%09ld", (s64)ts64.tv_sec, ts64.tv_nsec); - } - - if (fence->ops->timeline_value_str && - fence->ops->fence_value_str) { - char value[64]; - bool success; - - fence->ops->fence_value_str(fence, value, sizeof(value)); - success = strlen(value); - - if (success) { - seq_printf(s, ": %s", value); - - fence->ops->timeline_value_str(fence, value, - sizeof(value)); - - if (strlen(value)) - seq_printf(s, " / %s", value); - } - } - - seq_puts(s, "\n"); -} - -static void sync_print_obj(struct seq_file *s, struct sync_timeline *obj) -{ - struct list_head *pos; - unsigned long flags; - - seq_printf(s, "%s: %d\n", obj->name, obj->value); - - spin_lock_irqsave(&obj->child_list_lock, flags); - list_for_each(pos, &obj->child_list_head) { - struct sync_pt *pt = - container_of(pos, struct sync_pt, child_list); - sync_print_fence(s, &pt->base, false); - } - spin_unlock_irqrestore(&obj->child_list_lock, flags); -} - -static void sync_print_sync_file(struct seq_file *s, - struct sync_file *sync_file) -{ - int i; - - seq_printf(s, "[%p] %s: %s\n", sync_file, sync_file->name, - sync_status_str(atomic_read(&sync_file->status))); - - for (i = 0; i < sync_file->num_fences; ++i) - sync_print_fence(s, sync_file->cbs[i].fence, true); -} - -static int sync_debugfs_show(struct seq_file *s, void *unused) -{ - unsigned long flags; - struct list_head *pos; - - seq_puts(s, "objs:\n--------------\n"); - - spin_lock_irqsave(&sync_timeline_list_lock, flags); - list_for_each(pos, &sync_timeline_list_head) { - struct sync_timeline *obj = - container_of(pos, struct sync_timeline, - sync_timeline_list); - - sync_print_obj(s, obj); - seq_puts(s, "\n"); - } - spin_unlock_irqrestore(&sync_timeline_list_lock, flags); - - seq_puts(s, "fences:\n--------------\n"); - - spin_lock_irqsave(&sync_file_list_lock, flags); - list_for_each(pos, &sync_file_list_head) { - struct sync_file *sync_file = - container_of(pos, struct sync_file, sync_file_list); - - sync_print_sync_file(s, sync_file); - seq_puts(s, "\n"); - } - spin_unlock_irqrestore(&sync_file_list_lock, flags); - return 0; -} - -static int sync_info_debugfs_open(struct inode *inode, struct file *file) -{ - return single_open(file, sync_debugfs_show, inode->i_private); -} - -static const struct file_operations sync_info_debugfs_fops = { - .open = sync_info_debugfs_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static __init int sync_debugfs_init(void) -{ - dbgfs = debugfs_create_dir("sync", NULL); - - /* - * The debugfs files won't ever get removed and thus, there is - * no need to protect it against removal races. The use of - * debugfs_create_file_unsafe() is actually safe here. - */ - debugfs_create_file_unsafe("info", 0444, dbgfs, NULL, - &sync_info_debugfs_fops); - debugfs_create_file_unsafe("sw_sync", 0644, dbgfs, NULL, - &sw_sync_debugfs_fops); - - return 0; -} -late_initcall(sync_debugfs_init); - -#define DUMP_CHUNK 256 -static char sync_dump_buf[64 * 1024]; -void sync_dump(void) -{ - struct seq_file s = { - .buf = sync_dump_buf, - .size = sizeof(sync_dump_buf) - 1, - }; - int i; - - sync_debugfs_show(&s, NULL); - - for (i = 0; i < s.count; i += DUMP_CHUNK) { - if ((s.count - i) > DUMP_CHUNK) { - char c = s.buf[i + DUMP_CHUNK]; - - s.buf[i + DUMP_CHUNK] = 0; - pr_cont("%s", s.buf + i); - s.buf[i + DUMP_CHUNK] = c; - } else { - s.buf[s.count] = 0; - pr_cont("%s", s.buf + i); - } - } -} diff --git a/drivers/staging/android/sync_debug.h b/drivers/staging/android/sync_debug.h deleted file mode 100644 index d269aa6783aa..000000000000 --- a/drivers/staging/android/sync_debug.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Sync File validation framework and debug infomation - * - * Copyright (C) 2012 Google, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -#ifndef _LINUX_SYNC_H -#define _LINUX_SYNC_H - -#include -#include -#include - -#include -#include - -/** - * struct sync_timeline - sync object - * @kref: reference count on fence. - * @name: name of the sync_timeline. Useful for debugging - * @child_list_head: list of children sync_pts for this sync_timeline - * @child_list_lock: lock protecting @child_list_head and fence.status - * @active_list_head: list of active (unsignaled/errored) sync_pts - * @sync_timeline_list: membership in global sync_timeline_list - */ -struct sync_timeline { - struct kref kref; - char name[32]; - - /* protected by child_list_lock */ - u64 context; - int value; - - struct list_head child_list_head; - spinlock_t child_list_lock; - - struct list_head active_list_head; - - struct list_head sync_timeline_list; -}; - -static inline struct sync_timeline *fence_parent(struct fence *fence) -{ - return container_of(fence->lock, struct sync_timeline, - child_list_lock); -} - -/** - * struct sync_pt - sync_pt object - * @base: base fence object - * @child_list: sync timeline child's list - * @active_list: sync timeline active child's list - */ -struct sync_pt { - struct fence base; - struct list_head child_list; - struct list_head active_list; -}; - -#ifdef CONFIG_SW_SYNC - -extern const struct file_operations sw_sync_debugfs_fops; - -void sync_timeline_debug_add(struct sync_timeline *obj); -void sync_timeline_debug_remove(struct sync_timeline *obj); -void sync_file_debug_add(struct sync_file *fence); -void sync_file_debug_remove(struct sync_file *fence); -void sync_dump(void); - -#else -# define sync_timeline_debug_add(obj) -# define sync_timeline_debug_remove(obj) -# define sync_file_debug_add(fence) -# define sync_file_debug_remove(fence) -# define sync_dump() -#endif - -#endif /* _LINUX_SYNC_H */ diff --git a/drivers/staging/android/sync_trace.h b/drivers/staging/android/sync_trace.h deleted file mode 100644 index ea485f7be58a..000000000000 --- a/drivers/staging/android/sync_trace.h +++ /dev/null @@ -1,32 +0,0 @@ -#undef TRACE_SYSTEM -#define TRACE_INCLUDE_PATH ../../drivers/staging/android -#define TRACE_SYSTEM sync_trace - -#if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ) -#define _TRACE_SYNC_H - -#include "sync_debug.h" -#include - -TRACE_EVENT(sync_timeline, - TP_PROTO(struct sync_timeline *timeline), - - TP_ARGS(timeline), - - TP_STRUCT__entry( - __string(name, timeline->name) - __field(u32, value) - ), - - TP_fast_assign( - __assign_str(name, timeline->name); - __entry->value = timeline->value; - ), - - TP_printk("name=%s value=%d", __get_str(name), __entry->value) -); - -#endif /* if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ) */ - -/* This part must be outside protection */ -#include -- cgit v1.2.3 From 6a9aabb107c65ecb6f08b010853f5571d781ba5a Mon Sep 17 00:00:00 2001 From: Didik Setiawan Date: Sat, 14 May 2016 10:28:10 +0700 Subject: staging: android: ion: fix 'line over 80 characters' fix checkpatch.pl warning about 'line over 80 characters'. Signed-off-by: Didik Setiawan Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/ion/ion.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 7138a5b2bb10..88dd17e8b19a 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -545,7 +545,8 @@ struct ion_handle *ion_alloc(struct ion_client *client, size_t len, } EXPORT_SYMBOL(ion_alloc); -static void ion_free_nolock(struct ion_client *client, struct ion_handle *handle) +static void ion_free_nolock(struct ion_client *client, + struct ion_handle *handle) { bool valid_handle; @@ -1306,7 +1307,8 @@ static long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) struct ion_handle *handle; mutex_lock(&client->lock); - handle = ion_handle_get_by_id_nolock(client, data.handle.handle); + handle = ion_handle_get_by_id_nolock(client, + data.handle.handle); if (IS_ERR(handle)) { mutex_unlock(&client->lock); return PTR_ERR(handle); -- cgit v1.2.3 From 1e1f9ff406fd5f6003a5dab2ab5a26c4c5bb8cbd Mon Sep 17 00:00:00 2001 From: James Simmons Date: Mon, 20 Jun 2016 18:47:50 -0400 Subject: staging: lustre: llite: break ll_getxattr_common into 2 functions Split the function ll_getxattr_common into two functions. The code used for listing xattrs and ll_getxattr_common is placed into a new function ll_getxattr_list. This allows ll_listxattr to call directly ll_getxattr_list instead of going through ll_getxattr_common. This change is needed for the upcoming VFS move xattr_handler from [s|g]etxattr. Signed-off-by: James Simmons Signed-off-by: Greg Kroah-Hartman --- drivers/staging/lustre/lustre/llite/xattr.c | 122 ++++++++++++++-------------- 1 file changed, 62 insertions(+), 60 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/lustre/lustre/llite/xattr.c b/drivers/staging/lustre/lustre/llite/xattr.c index 98303cf85815..a034a5f61d22 100644 --- a/drivers/staging/lustre/lustre/llite/xattr.c +++ b/drivers/staging/lustre/lustre/llite/xattr.c @@ -217,69 +217,18 @@ int ll_removexattr(struct dentry *dentry, const char *name) OBD_MD_FLXATTRRM); } -static -int ll_getxattr_common(struct inode *inode, const char *name, - void *buffer, size_t size, __u64 valid) +static int +ll_xattr_list(struct inode *inode, const char *name, int type, void *buffer, + size_t size, __u64 valid) { + struct ll_inode_info *lli = ll_i2info(inode); struct ll_sb_info *sbi = ll_i2sbi(inode); struct ptlrpc_request *req = NULL; struct mdt_body *body; - int xattr_type, rc; void *xdata; - struct ll_inode_info *lli = ll_i2info(inode); - - CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n", - PFID(ll_inode2fid(inode)), inode); - - /* listxattr have slightly different behavior from of ext3: - * without 'user_xattr' ext3 will list all xattr names but - * filtered out "^user..*"; we list them all for simplicity. - */ - if (!name) { - xattr_type = XATTR_OTHER_T; - goto do_getxattr; - } - - xattr_type = get_xattr_type(name); - rc = xattr_type_filter(sbi, xattr_type); - if (rc) - return rc; - - /* b15587: ignore security.capability xattr for now */ - if ((xattr_type == XATTR_SECURITY_T && - strcmp(name, "security.capability") == 0)) - return -ENODATA; - - /* LU-549: Disable security.selinux when selinux is disabled */ - if (xattr_type == XATTR_SECURITY_T && !selinux_is_enabled() && - strcmp(name, "security.selinux") == 0) - return -EOPNOTSUPP; - -#ifdef CONFIG_FS_POSIX_ACL - /* posix acl is under protection of LOOKUP lock. when calling to this, - * we just have path resolution to the target inode, so we have great - * chance that cached ACL is uptodate. - */ - if (xattr_type == XATTR_ACL_ACCESS_T) { - struct posix_acl *acl; - - spin_lock(&lli->lli_lock); - acl = posix_acl_dup(lli->lli_posix_acl); - spin_unlock(&lli->lli_lock); - - if (!acl) - return -ENODATA; - - rc = posix_acl_to_xattr(&init_user_ns, acl, buffer, size); - posix_acl_release(acl); - return rc; - } - if (xattr_type == XATTR_ACL_DEFAULT_T && !S_ISDIR(inode->i_mode)) - return -ENODATA; -#endif + int rc; -do_getxattr: - if (sbi->ll_xattr_cache_enabled && xattr_type != XATTR_ACL_ACCESS_T) { + if (sbi->ll_xattr_cache_enabled && type != XATTR_ACL_ACCESS_T) { rc = ll_xattr_cache_get(inode, name, buffer, size, valid); if (rc == -EAGAIN) goto getxattr_nocache; @@ -340,7 +289,7 @@ getxattr_nocache: } out_xattr: - if (rc == -EOPNOTSUPP && xattr_type == XATTR_USER_T) { + if (rc == -EOPNOTSUPP && type == XATTR_USER_T) { LCONSOLE_INFO( "%s: disabling user_xattr feature because it is not supported on the server: rc = %d\n", ll_get_fsname(inode->i_sb, NULL, 0), rc); @@ -351,6 +300,58 @@ out: return rc; } +static +int ll_getxattr_common(struct inode *inode, const char *name, + void *buffer, size_t size) +{ + struct ll_sb_info *sbi = ll_i2sbi(inode); + int xattr_type, rc; + struct ll_inode_info *lli = ll_i2info(inode); + + CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n", + PFID(ll_inode2fid(inode)), inode); + + xattr_type = get_xattr_type(name); + rc = xattr_type_filter(sbi, xattr_type); + if (rc) + return rc; + + /* b15587: ignore security.capability xattr for now */ + if ((xattr_type == XATTR_SECURITY_T && + strcmp(name, "security.capability") == 0)) + return -ENODATA; + + /* LU-549: Disable security.selinux when selinux is disabled */ + if (xattr_type == XATTR_SECURITY_T && !selinux_is_enabled() && + strcmp(name, "security.selinux") == 0) + return -EOPNOTSUPP; + +#ifdef CONFIG_FS_POSIX_ACL + /* posix acl is under protection of LOOKUP lock. when calling to this, + * we just have path resolution to the target inode, so we have great + * chance that cached ACL is uptodate. + */ + if (xattr_type == XATTR_ACL_ACCESS_T) { + struct posix_acl *acl; + + spin_lock(&lli->lli_lock); + acl = posix_acl_dup(lli->lli_posix_acl); + spin_unlock(&lli->lli_lock); + + if (!acl) + return -ENODATA; + + rc = posix_acl_to_xattr(&init_user_ns, acl, buffer, size); + posix_acl_release(acl); + return rc; + } + if (xattr_type == XATTR_ACL_DEFAULT_T && !S_ISDIR(inode->i_mode)) + return -ENODATA; +#endif + return ll_xattr_list(inode, name, xattr_type, buffer, size, + OBD_MD_FLXATTR); +} + ssize_t ll_getxattr(struct dentry *dentry, struct inode *inode, const char *name, void *buffer, size_t size) { @@ -439,7 +440,7 @@ out: return rc; } - return ll_getxattr_common(inode, name, buffer, size, OBD_MD_FLXATTR); + return ll_getxattr_common(inode, name, buffer, size); } ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size) @@ -457,7 +458,8 @@ ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size) ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_LISTXATTR, 1); - rc = ll_getxattr_common(inode, NULL, buffer, size, OBD_MD_FLXATTRLS); + rc = ll_xattr_list(inode, NULL, XATTR_OTHER_T, buffer, size, + OBD_MD_FLXATTRLS); if (rc < 0) goto out; -- cgit v1.2.3 From 1b851095d64e55a4345cddf4928256b1452b25ed Mon Sep 17 00:00:00 2001 From: Ben Evans Date: Wed, 22 Jun 2016 11:19:54 -0400 Subject: staging: lustre: lnet: Remove old commented out code These #if 0 blocks have been in place for years. Assume they are not used and remove them Signed-off-by: Ben Evans Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-8058 Reviewed-on: http://review.whamcloud.com/20414 Reviewed-by: Andreas Dilger Reviewed-by: James Simmons Reviewed-by: Oleg Drokin Signed-off-by: James Simmons Signed-off-by: Greg Kroah-Hartman --- drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c | 5 ----- drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 7 ------- drivers/staging/lustre/lnet/lnet/lib-msg.c | 18 +----------------- 3 files changed, 1 insertion(+), 29 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c index 07ec540946cd..cbc9a9c5385f 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c @@ -1468,11 +1468,6 @@ ksocknal_close_conn_locked(struct ksock_conn *conn, int error) conn->ksnc_route = NULL; -#if 0 /* irrelevant with only eager routes */ - /* make route least favourite */ - list_del(&route->ksnr_list); - list_add_tail(&route->ksnr_list, &peer->ksnp_routes); -#endif ksocknal_route_decref(route); /* drop conn's ref on route */ } diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c index 303576d815c6..d53da552bd61 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c @@ -2008,13 +2008,6 @@ ksocknal_connect(struct ksock_route *route) list_splice_init(&peer->ksnp_tx_queue, &zombies); } -#if 0 /* irrelevant with only eager routes */ - if (!route->ksnr_deleted) { - /* make this route least-favourite for re-selection */ - list_del(&route->ksnr_list); - list_add_tail(&route->ksnr_list, &peer->ksnp_routes); - } -#endif write_unlock_bh(&ksocknal_data.ksnd_global_lock); ksocknal_peer_failed(peer); diff --git a/drivers/staging/lustre/lnet/lnet/lib-msg.c b/drivers/staging/lustre/lnet/lnet/lib-msg.c index 910e106e221d..0897e588bd54 100644 --- a/drivers/staging/lustre/lnet/lnet/lib-msg.c +++ b/drivers/staging/lustre/lnet/lnet/lib-msg.c @@ -449,23 +449,7 @@ lnet_finalize(lnet_ni_t *ni, lnet_msg_t *msg, int status) if (!msg) return; -#if 0 - CDEBUG(D_WARNING, "%s msg->%s Flags:%s%s%s%s%s%s%s%s%s%s%s txp %s rxp %s\n", - lnet_msgtyp2str(msg->msg_type), libcfs_id2str(msg->msg_target), - msg->msg_target_is_router ? "t" : "", - msg->msg_routing ? "X" : "", - msg->msg_ack ? "A" : "", - msg->msg_sending ? "S" : "", - msg->msg_receiving ? "R" : "", - msg->msg_delayed ? "d" : "", - msg->msg_txcredit ? "C" : "", - msg->msg_peertxcredit ? "c" : "", - msg->msg_rtrcredit ? "F" : "", - msg->msg_peerrtrcredit ? "f" : "", - msg->msg_onactivelist ? "!" : "", - !msg->msg_txpeer ? "" : libcfs_nid2str(msg->msg_txpeer->lp_nid), - !msg->msg_rxpeer ? "" : libcfs_nid2str(msg->msg_rxpeer->lp_nid)); -#endif + msg->msg_ev.status = status; if (msg->msg_md) { -- cgit v1.2.3 From 2c563880ea8fdc900693ae372fa07b3894f8ff63 Mon Sep 17 00:00:00 2001 From: James Simmons Date: Mon, 11 Jul 2016 09:40:10 -0400 Subject: staging: lustre: llite: basic port to xattr_handler API Port the xattr functionality to the new xattr_handler API. This is smallest changes needed to move to this new API. The function ll_removexattr can be replaced by generic_removexattr as well since it also uses the xattr_handler set xattr backend. To tell the difference between the two cases we test the flag passed in for XATTR_REPLACE. The ll_getxattr function is replaced by the generic_getxattr function. Signed-off-by: James Simmons Signed-off-by: Greg Kroah-Hartman --- drivers/staging/lustre/lustre/llite/file.c | 6 +- .../staging/lustre/lustre/llite/llite_internal.h | 8 +- drivers/staging/lustre/lustre/llite/llite_lib.c | 1 + drivers/staging/lustre/lustre/llite/namei.c | 12 +- drivers/staging/lustre/lustre/llite/symlink.c | 6 +- drivers/staging/lustre/lustre/llite/xattr.c | 195 +++++++++++++-------- 6 files changed, 141 insertions(+), 87 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/lustre/lustre/llite/file.c b/drivers/staging/lustre/lustre/llite/file.c index 57281b9e31ff..58a7401046e0 100644 --- a/drivers/staging/lustre/lustre/llite/file.c +++ b/drivers/staging/lustre/lustre/llite/file.c @@ -3213,10 +3213,10 @@ const struct inode_operations ll_file_inode_operations = { .setattr = ll_setattr, .getattr = ll_getattr, .permission = ll_inode_permission, - .setxattr = ll_setxattr, - .getxattr = ll_getxattr, + .setxattr = generic_setxattr, + .getxattr = generic_getxattr, .listxattr = ll_listxattr, - .removexattr = ll_removexattr, + .removexattr = generic_removexattr, .fiemap = ll_fiemap, .get_acl = ll_get_acl, }; diff --git a/drivers/staging/lustre/lustre/llite/llite_internal.h b/drivers/staging/lustre/lustre/llite/llite_internal.h index 4d6d589a1677..27d3f7706d44 100644 --- a/drivers/staging/lustre/lustre/llite/llite_internal.h +++ b/drivers/staging/lustre/lustre/llite/llite_internal.h @@ -42,6 +42,7 @@ #include "../include/lustre_mdc.h" #include "../include/lustre_intent.h" #include +#include #include #include "vvp_internal.h" @@ -933,12 +934,9 @@ static inline __u64 ll_file_maxbytes(struct inode *inode) } /* llite/xattr.c */ -int ll_setxattr(struct dentry *dentry, struct inode *inode, - const char *name, const void *value, size_t size, int flags); -ssize_t ll_getxattr(struct dentry *dentry, struct inode *inode, - const char *name, void *buffer, size_t size); +extern const struct xattr_handler *ll_xattr_handlers[]; + ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size); -int ll_removexattr(struct dentry *dentry, const char *name); /** * Common IO arguments for various VFS I/O interfaces. diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c index 546063e728db..75d568f5bb90 100644 --- a/drivers/staging/lustre/lustre/llite/llite_lib.c +++ b/drivers/staging/lustre/lustre/llite/llite_lib.c @@ -418,6 +418,7 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt, CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid)); sb->s_op = &lustre_super_operations; + sb->s_xattr = ll_xattr_handlers; #if THREAD_SIZE >= 8192 /*b=17630*/ sb->s_export_op = &lustre_export_operations; #endif diff --git a/drivers/staging/lustre/lustre/llite/namei.c b/drivers/staging/lustre/lustre/llite/namei.c index 3664bfd0178b..1e75f5b09c31 100644 --- a/drivers/staging/lustre/lustre/llite/namei.c +++ b/drivers/staging/lustre/lustre/llite/namei.c @@ -1101,10 +1101,10 @@ const struct inode_operations ll_dir_inode_operations = { .setattr = ll_setattr, .getattr = ll_getattr, .permission = ll_inode_permission, - .setxattr = ll_setxattr, - .getxattr = ll_getxattr, + .setxattr = generic_setxattr, + .getxattr = generic_getxattr, .listxattr = ll_listxattr, - .removexattr = ll_removexattr, + .removexattr = generic_removexattr, .get_acl = ll_get_acl, }; @@ -1112,9 +1112,9 @@ const struct inode_operations ll_special_inode_operations = { .setattr = ll_setattr, .getattr = ll_getattr, .permission = ll_inode_permission, - .setxattr = ll_setxattr, - .getxattr = ll_getxattr, + .setxattr = generic_setxattr, + .getxattr = generic_getxattr, .listxattr = ll_listxattr, - .removexattr = ll_removexattr, + .removexattr = generic_removexattr, .get_acl = ll_get_acl, }; diff --git a/drivers/staging/lustre/lustre/llite/symlink.c b/drivers/staging/lustre/lustre/llite/symlink.c index 8c8bdfe1ad71..4601be94dd22 100644 --- a/drivers/staging/lustre/lustre/llite/symlink.c +++ b/drivers/staging/lustre/lustre/llite/symlink.c @@ -155,8 +155,8 @@ const struct inode_operations ll_fast_symlink_inode_operations = { .get_link = ll_get_link, .getattr = ll_getattr, .permission = ll_inode_permission, - .setxattr = ll_setxattr, - .getxattr = ll_getxattr, + .setxattr = generic_setxattr, + .getxattr = generic_getxattr, .listxattr = ll_listxattr, - .removexattr = ll_removexattr, + .removexattr = generic_removexattr, }; diff --git a/drivers/staging/lustre/lustre/llite/xattr.c b/drivers/staging/lustre/lustre/llite/xattr.c index a034a5f61d22..a02b80269b5c 100644 --- a/drivers/staging/lustre/lustre/llite/xattr.c +++ b/drivers/staging/lustre/lustre/llite/xattr.c @@ -99,46 +99,57 @@ int xattr_type_filter(struct ll_sb_info *sbi, int xattr_type) return 0; } -static -int ll_setxattr_common(struct inode *inode, const char *name, - const void *value, size_t size, - int flags, __u64 valid) +static int +ll_xattr_set_common(const struct xattr_handler *handler, + struct dentry *dentry, struct inode *inode, + const char *name, const void *value, size_t size, + int flags) { + char fullname[strlen(handler->prefix) + strlen(name) + 1]; struct ll_sb_info *sbi = ll_i2sbi(inode); struct ptlrpc_request *req = NULL; - int xattr_type, rc; const char *pv = value; + __u64 valid; + int rc; - xattr_type = get_xattr_type(name); - rc = xattr_type_filter(sbi, xattr_type); + if (flags == XATTR_REPLACE) { + ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_REMOVEXATTR, 1); + valid = OBD_MD_FLXATTRRM; + } else { + ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_SETXATTR, 1); + valid = OBD_MD_FLXATTR; + } + + rc = xattr_type_filter(sbi, handler->flags); if (rc) return rc; - if ((xattr_type == XATTR_ACL_ACCESS_T || - xattr_type == XATTR_ACL_DEFAULT_T) && + if ((handler->flags == XATTR_ACL_ACCESS_T || + handler->flags == XATTR_ACL_DEFAULT_T) && !inode_owner_or_capable(inode)) return -EPERM; /* b10667: ignore lustre special xattr for now */ - if ((xattr_type == XATTR_TRUSTED_T && strcmp(name, "trusted.lov") == 0) || - (xattr_type == XATTR_LUSTRE_T && strcmp(name, "lustre.lov") == 0)) + if ((handler->flags == XATTR_TRUSTED_T && !strcmp(name, "lov")) || + (handler->flags == XATTR_LUSTRE_T && !strcmp(name, "lov"))) return 0; /* b15587: ignore security.capability xattr for now */ - if ((xattr_type == XATTR_SECURITY_T && - strcmp(name, "security.capability") == 0)) + if ((handler->flags == XATTR_SECURITY_T && + !strcmp(name, "capability"))) return 0; /* LU-549: Disable security.selinux when selinux is disabled */ - if (xattr_type == XATTR_SECURITY_T && !selinux_is_enabled() && - strcmp(name, "security.selinux") == 0) + if (handler->flags == XATTR_SECURITY_T && !selinux_is_enabled() && + strcmp(name, "selinux") == 0) return -EOPNOTSUPP; + sprintf(fullname, "%s%s\n", handler->prefix, name); rc = md_setxattr(sbi->ll_md_exp, ll_inode2fid(inode), - valid, name, pv, size, 0, flags, + valid, fullname, pv, size, 0, flags, ll_i2suppgid(inode), &req); if (rc) { - if (rc == -EOPNOTSUPP && xattr_type == XATTR_USER_T) { + if (rc == -EOPNOTSUPP && handler->flags == XATTR_USER_T) { LCONSOLE_INFO("Disabling user_xattr feature because it is not supported on the server\n"); sbi->ll_flags &= ~LL_SBI_USER_XATTR; } @@ -149,8 +160,10 @@ int ll_setxattr_common(struct inode *inode, const char *name, return 0; } -int ll_setxattr(struct dentry *dentry, struct inode *inode, - const char *name, const void *value, size_t size, int flags) +static int ll_xattr_set(const struct xattr_handler *handler, + struct dentry *dentry, struct inode *inode, + const char *name, const void *value, size_t size, + int flags) { LASSERT(inode); LASSERT(name); @@ -158,20 +171,24 @@ int ll_setxattr(struct dentry *dentry, struct inode *inode, CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), xattr %s\n", PFID(ll_inode2fid(inode)), inode, name); - ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_SETXATTR, 1); - - if ((strncmp(name, XATTR_TRUSTED_PREFIX, - sizeof(XATTR_TRUSTED_PREFIX) - 1) == 0 && - strcmp(name + sizeof(XATTR_TRUSTED_PREFIX) - 1, "lov") == 0) || - (strncmp(name, XATTR_LUSTRE_PREFIX, - sizeof(XATTR_LUSTRE_PREFIX) - 1) == 0 && - strcmp(name + sizeof(XATTR_LUSTRE_PREFIX) - 1, "lov") == 0)) { + if (!strcmp(name, "lov")) { struct lov_user_md *lump = (struct lov_user_md *)value; + int op_type = flags == XATTR_REPLACE ? LPROC_LL_REMOVEXATTR : + LPROC_LL_SETXATTR; int rc = 0; + ll_stats_ops_tally(ll_i2sbi(inode), op_type, 1); + if (size != 0 && size < sizeof(struct lov_user_md)) return -EINVAL; + /* + * It is possible to set an xattr to a "" value of zero size. + * For this case we are going to treat it as a removal. + */ + if (!size && lump) + lump = NULL; + /* Attributes that are saved via getxattr will always have * the stripe_offset as 0. Instead, the MDS should be * allowed to pick the starting OST index. b=17846 @@ -194,27 +211,13 @@ int ll_setxattr(struct dentry *dentry, struct inode *inode, return rc; - } else if (strcmp(name, XATTR_NAME_LMA) == 0 || - strcmp(name, XATTR_NAME_LINK) == 0) + } else if (!strcmp(name, "lma") || !strcmp(name, "link")) { + ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_SETXATTR, 1); return 0; + } - return ll_setxattr_common(inode, name, value, size, flags, - OBD_MD_FLXATTR); -} - -int ll_removexattr(struct dentry *dentry, const char *name) -{ - struct inode *inode = d_inode(dentry); - - LASSERT(inode); - LASSERT(name); - - CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), xattr %s\n", - PFID(ll_inode2fid(inode)), inode, name); - - ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_REMOVEXATTR, 1); - return ll_setxattr_common(inode, name, NULL, 0, 0, - OBD_MD_FLXATTRRM); + return ll_xattr_set_common(handler, dentry, inode, name, value, size, + flags); } static int @@ -300,30 +303,31 @@ out: return rc; } -static -int ll_getxattr_common(struct inode *inode, const char *name, - void *buffer, size_t size) +static int ll_xattr_get_common(const struct xattr_handler *handler, + struct dentry *dentry, struct inode *inode, + const char *name, void *buffer, size_t size) { + char fullname[strlen(handler->prefix) + strlen(name) + 1]; struct ll_sb_info *sbi = ll_i2sbi(inode); - int xattr_type, rc; struct ll_inode_info *lli = ll_i2info(inode); + int rc; CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n", PFID(ll_inode2fid(inode)), inode); - xattr_type = get_xattr_type(name); - rc = xattr_type_filter(sbi, xattr_type); + ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_GETXATTR, 1); + + rc = xattr_type_filter(sbi, handler->flags); if (rc) return rc; /* b15587: ignore security.capability xattr for now */ - if ((xattr_type == XATTR_SECURITY_T && - strcmp(name, "security.capability") == 0)) + if ((handler->flags == XATTR_SECURITY_T && !strcmp(name, "capability"))) return -ENODATA; /* LU-549: Disable security.selinux when selinux is disabled */ - if (xattr_type == XATTR_SECURITY_T && !selinux_is_enabled() && - strcmp(name, "security.selinux") == 0) + if (handler->flags == XATTR_SECURITY_T && !selinux_is_enabled() && + !strcmp(name, "selinux")) return -EOPNOTSUPP; #ifdef CONFIG_FS_POSIX_ACL @@ -331,7 +335,7 @@ int ll_getxattr_common(struct inode *inode, const char *name, * we just have path resolution to the target inode, so we have great * chance that cached ACL is uptodate. */ - if (xattr_type == XATTR_ACL_ACCESS_T) { + if (handler->flags == XATTR_ACL_ACCESS_T) { struct posix_acl *acl; spin_lock(&lli->lli_lock); @@ -345,15 +349,17 @@ int ll_getxattr_common(struct inode *inode, const char *name, posix_acl_release(acl); return rc; } - if (xattr_type == XATTR_ACL_DEFAULT_T && !S_ISDIR(inode->i_mode)) + if (handler->flags == XATTR_ACL_DEFAULT_T && !S_ISDIR(inode->i_mode)) return -ENODATA; #endif - return ll_xattr_list(inode, name, xattr_type, buffer, size, + sprintf(fullname, "%s%s\n", handler->prefix, name); + return ll_xattr_list(inode, fullname, handler->flags, buffer, size, OBD_MD_FLXATTR); } -ssize_t ll_getxattr(struct dentry *dentry, struct inode *inode, - const char *name, void *buffer, size_t size) +static int ll_xattr_get(const struct xattr_handler *handler, + struct dentry *dentry, struct inode *inode, + const char *name, void *buffer, size_t size) { LASSERT(inode); LASSERT(name); @@ -361,20 +367,15 @@ ssize_t ll_getxattr(struct dentry *dentry, struct inode *inode, CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), xattr %s\n", PFID(ll_inode2fid(inode)), inode, name); - ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_GETXATTR, 1); - - if ((strncmp(name, XATTR_TRUSTED_PREFIX, - sizeof(XATTR_TRUSTED_PREFIX) - 1) == 0 && - strcmp(name + sizeof(XATTR_TRUSTED_PREFIX) - 1, "lov") == 0) || - (strncmp(name, XATTR_LUSTRE_PREFIX, - sizeof(XATTR_LUSTRE_PREFIX) - 1) == 0 && - strcmp(name + sizeof(XATTR_LUSTRE_PREFIX) - 1, "lov") == 0)) { + if (!strcmp(name, "lov")) { struct lov_stripe_md *lsm; struct lov_user_md *lump; struct lov_mds_md *lmm = NULL; struct ptlrpc_request *request = NULL; int rc = 0, lmmsize = 0; + ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_GETXATTR, 1); + if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode)) return -ENODATA; @@ -440,7 +441,7 @@ out: return rc; } - return ll_getxattr_common(inode, name, buffer, size); + return ll_xattr_get_common(handler, dentry, inode, name, buffer, size); } ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size) @@ -520,3 +521,57 @@ out: return rc; } + +static const struct xattr_handler ll_user_xattr_handler = { + .prefix = XATTR_USER_PREFIX, + .flags = XATTR_USER_T, + .get = ll_xattr_get_common, + .set = ll_xattr_set_common, +}; + +static const struct xattr_handler ll_trusted_xattr_handler = { + .prefix = XATTR_TRUSTED_PREFIX, + .flags = XATTR_TRUSTED_T, + .get = ll_xattr_get, + .set = ll_xattr_set, +}; + +static const struct xattr_handler ll_security_xattr_handler = { + .prefix = XATTR_SECURITY_PREFIX, + .flags = XATTR_SECURITY_T, + .get = ll_xattr_get_common, + .set = ll_xattr_set_common, +}; + +static const struct xattr_handler ll_acl_access_xattr_handler = { + .prefix = XATTR_NAME_POSIX_ACL_ACCESS, + .flags = XATTR_ACL_ACCESS_T, + .get = ll_xattr_get_common, + .set = ll_xattr_set_common, +}; + +static const struct xattr_handler ll_acl_default_xattr_handler = { + .prefix = XATTR_NAME_POSIX_ACL_DEFAULT, + .flags = XATTR_ACL_DEFAULT_T, + .get = ll_xattr_get_common, + .set = ll_xattr_set_common, +}; + +static const struct xattr_handler ll_lustre_xattr_handler = { + .prefix = XATTR_LUSTRE_PREFIX, + .flags = XATTR_LUSTRE_T, + .get = ll_xattr_get, + .set = ll_xattr_set, +}; + +const struct xattr_handler *ll_xattr_handlers[] = { + &ll_user_xattr_handler, + &ll_trusted_xattr_handler, + &ll_security_xattr_handler, +#ifdef CONFIG_FS_POSIX_ACL + &ll_acl_access_xattr_handler, + &ll_acl_default_xattr_handler, +#endif + &ll_lustre_xattr_handler, + NULL, +}; -- cgit v1.2.3